<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Square MI &#187; PHP</title>
	<atom:link href="http://www.square-mi.com/wp/category/development/php-language/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.square-mi.com/wp</link>
	<description>oracle, php, java, etc... technical memo &#38; つれづれなこと</description>
	<lastBuildDate>Tue, 12 Feb 2013 12:22:08 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>Notice: Undefined offset &#8230; PHPExcel.php on line 191</title>
		<link>http://www.square-mi.com/wp/263/notice-undefined-offset-phpexcel-php-on-line-191/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=notice-undefined-offset-phpexcel-php-on-line-191</link>
		<comments>http://www.square-mi.com/wp/263/notice-undefined-offset-phpexcel-php-on-line-191/#comments</comments>
		<pubDate>Thu, 01 Nov 2012 06:00:13 +0000</pubDate>
		<dc:creator>commerce</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPExcel]]></category>
		<category><![CDATA[開発]]></category>

		<guid isPermaLink="false">http://www.square-mi.com/wp/?p=263</guid>
		<description><![CDATA[で、掲題の Notice: Undefined offset &#8230; PHPExcel.php on line 191 が、出てしまう。 出現箇所は、 $writer-&#62;save(&#8216;new.xl &#8230; <a href="http://www.square-mi.com/wp/263/notice-undefined-offset-phpexcel-php-on-line-191/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<pre class="brush: php; light: true; title: ; notranslate">
$reader = PHPExcel_IOFactory::createReader('Excel5');
$excel = $reader-&gt;load('template.xls');
$tempSheet = $excel-&gt;getSheet(0);

for( ある回数分繰り返し ) {
  $cloneSheet = $tempSheet-&gt;copy();
  $excel-&gt;addSheet( $cloneSheet );
  ( $cloneSheet への編集処理 )
}

$excel-&gt;removeSheetByIndex( 0 );

$writer =
  PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$writer-&gt;save('new.xls');
</pre>
<p>で、掲題の<br />
Notice: Undefined offset &#8230; PHPExcel.php on line 191<br />
が、出てしまう。</p>
<p>出現箇所は、<br />
$writer-&gt;save(&#8216;new.xls&#8217;);</p>
<p>編集処理のところに</p>
<p>$cloneSheet-&gt;getStyle(&#8216;A1&#8242;)-&gt;getFont()-&gt;setBold(true);</p>
<p>を入れた時点で、このメッセージが出るようになった。</p>
<p>それで、メッセージ内容に従い、PHPExcel.php 191行目をみてみると getActiveSheet() の中で出ていることが判明。</p>
<p>echo &#8220;count=&#8221; . $this-&gt;_workSheetCollection;<br />
echo &#8220;index=&#8221; . $this-&gt;_activeSheetIndex;</p>
<p>とやって、配列数とインデックスを表示するという調査を行ったところ、</p>
<p>$excel-&gt;removeSheetByIndex(0)</p>
<p>でシート削除した後も</p>
<p>$excel-&gt;addSheet()</p>
<p>した、最終Sheetのインデックスを$this-&gt;_activeSheetIndex<br />
として、内部で持っているようである。</p>
<p>なので、シート削除直後に</p>
<p><strong>$excel-&gt;setActiveSheetIndex(0);</strong></p>
<p>を挿入することで、掲題のメッセージは表示されなくなった。</p>
<p>なんか、バグっぽい！！</p>
<p>それともうひとつ、</p>
<p>$cloneSheet への編集処理を</p>
<p>$excel-&gt;addSheet( $cloneSheet );</p>
<p>の後で行なっているのは何故か？</p>
<p>先に編集処理を行うと、また　編集処理中の setBold() のせいで</p>
<h4>PHP Fatal error:  Call to a member function getStyle() on a non-object in Style/Font.php on line 386</h4>
<p>になってしまう。</p>
<p>それで、またメッセージ内容に従い、Font.php 386行目を見てみた。</p>
<p>$this-&gt;getActiveSheet()-&gt;getStyle(&#8230;);</p>
<p>でエラーになっているらしい。</p>
<p>つまり、コピーしたばかりの $cloneSheet には、所属するBook(PHPExcelオブジェクト)がなく、getActiveSheet() が失敗するということらしい。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.square-mi.com/wp/263/notice-undefined-offset-phpexcel-php-on-line-191/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Warning</title>
		<link>http://www.square-mi.com/wp/217/php-warning/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-warning</link>
		<comments>http://www.square-mi.com/wp/217/php-warning/#comments</comments>
		<pubDate>Mon, 22 Oct 2012 03:42:56 +0000</pubDate>
		<dc:creator>commerce</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.square-mi.com/wp/?p=217</guid>
		<description><![CDATA[PHP Warning:  date(): It is not safe to rely on the system&#8217;s timezone settings. You are *required* to us &#8230; <a href="http://www.square-mi.com/wp/217/php-warning/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h4>PHP Warning:  date(): It is not safe to rely on the system&#8217;s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.</h4>
<p>読んで字の通り、php.ini に</p>
<pre class="brush: bash; light: true; title: ; notranslate">date.timezone = 'Asia/Tokyo'</pre>
<p>とするか、コード中に</p>
<pre class="brush: php; light: true; title: ; notranslate">date_default_timezone_set('Asia/Tokyo')</pre>
<p>とすれば、このワーニングはなくなる。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.square-mi.com/wp/217/php-warning/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHPフレームワークsymfonyをインストールする</title>
		<link>http://www.square-mi.com/wp/138/php%e3%83%95%e3%83%ac%e3%83%bc%e3%83%a0%e3%83%af%e3%83%bc%e3%82%afsymfony%e3%82%92%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php%25e3%2583%2595%25e3%2583%25ac%25e3%2583%25bc%25e3%2583%25a0%25e3%2583%25af%25e3%2583%25bc%25e3%2582%25afsymfony%25e3%2582%2592%25e3%2582%25a4%25e3%2583%25b3%25e3%2582%25b9%25e3%2583%2588%25e3%2583%25bc%25e3%2583%25ab%25e3%2581%2599%25e3%2582%258b</link>
		<comments>http://www.square-mi.com/wp/138/php%e3%83%95%e3%83%ac%e3%83%bc%e3%83%a0%e3%83%af%e3%83%bc%e3%82%afsymfony%e3%82%92%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Wed, 17 Oct 2012 03:33:47 +0000</pubDate>
		<dc:creator>commerce</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[開発]]></category>

		<guid isPermaLink="false">http://www.square-mi.com/wp/?p=138</guid>
		<description><![CDATA[PHP上で動作するアプリケーション開発フレームワーク symfony を導入します。プロジェクト，アプリケーション，モジュールを作成し、ブラウザで確認するところまでをまとめました。　http://www.symfony- &#8230; <a href="http://www.square-mi.com/wp/138/php%e3%83%95%e3%83%ac%e3%83%bc%e3%83%a0%e3%83%af%e3%83%bc%e3%82%afsymfony%e3%82%92%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>PHP上で動作するアプリケーション開発フレームワーク symfony を導入します。プロジェクト，アプリケーション，モジュールを作成し、ブラウザで確認するところまでをまとめました。　<a href="http://www.symfony-project.org/" target="_blank">http://www.symfony-project.org</a> を参考にしていますので、詳細はそちらをご覧ください。</p>
<p>下記環境に PEAR を用いて <strong>symfony 1.4.19</strong> をインストールしました。</p>
<p style="padding-left: 30px">CentOS 6.2 x86_64(サーバー名:centos6)</p>
<p style="padding-left: 30px">Apache 2.2.15</p>
<p style="padding-left: 30px">PHP 5.3.3 (Zend Engine v2.3.0)</p>
<p style="padding-left: 30px">　symfonyはMITライセンスに基づいています。　商用利用もOKで、GPLなどとは違い、コピーレフトではなく（二次著作物のライセンス変更可）ソースコードを公開する必要もないので、ライセンスについてあまり気にする必要はありません。（著作権表示の義務はありますが）</p>
<h3>symfonyのインストール</h3>
<p style="padding-left: 30px">root で実行しました。</p>
<ol>
<li>pearを アップグレード
<pre class="brush: bash; light: true; title: ; notranslate">$ pear upgrade PEAR
Nothing to upgrade</pre>
</li>
<li>symfonyのチャネルに接続
<pre class="brush: bash; light: true; title: ; notranslate">$ pear channel-discover pear.symfony-project.com
Adding Channel &quot;pear.symfony-project.com&quot; succeeded
Discovery of channel &quot;pear.symfony-project.com&quot; succeeded</pre>
</li>
<li>インストールの実行
<pre class="brush: bash; highlight: [1]; light: true; title: ; notranslate">$ pear install symfony/symfony-beta
downloading symfony-1.4.19.tgz ...
Starting to download symfony-1.4.19.tgz(3,188,169 bytes)
......................................................
......................................................
......................................................
......................................................
......................................................
......................................................
......................................................
done: 3,188,169 bytes
install ok:
channel://pear.symfony-project.com/symfony-1.4.19</pre>
</li>
<li>確認（バージョンを表示してみる）
<pre class="brush: bash; light: true; title: ; notranslate">$ symfony -V
symfony version 1.4.19 (/usr/share/pear/symfony)</pre>
</li>
</ol>
<h3> プロジェクトの作成</h3>
<p style="padding-left: 30px"> Linux user <strong>smi</strong> でディレクトリ &#8220;/home/smi&#8221; 配下に作成しました。</p>
<ol>
<li> プロジェクト &#8220;jobeet&#8221; を作成する。
<pre class="brush: bash; highlight: [4]; light: true; title: ; notranslate">$ cd /home/smi
$ mkdir jobeet
$ cd jobeet
$ symfony generate:project jobeet</pre>
</li>
<li>/home/smi/jobeet 配下に symfony プロジェクトに必要な以下ディレクトリが作成される。<br />
apps/ プロジェクトのすべてのアプリケーションを格納する<br />
cache/ フレームワークによってキャッシュされるファイル<br />
config/ プロジェクトの設定ファイル<br />
data/<br />
lib/ プロジェクトのライブラリとクラス<br />
log/ フレームワークのログファイル<br />
plugins/ インストールされたプラグイン<br />
test/ ユニットテストと機能テストのファイル<br />
web/ Web 公開ルートディレクトリ</li>
</ol>
<h3><span style="font-size: 14px;line-height: 23px">アプリケーションの作成</span></h3>
<ol>
<li>アプリケーション &#8220;frontend&#8221; を作成する
<pre class="brush: bash; light: true; title: ; notranslate">$ symfony generate:app frontend</pre>
</li>
<li>/home/smi/jobeet/apps/frontend 配下にアプリケーションに必要な以下ディレクトリが作成される。<br />
config/ アプリケーションの設定ファイル<br />
i18n/<br />
lib/ アプリケーションのライブラリとクラス<br />
modules/ アプリケーションのコード (MVC)<br />
templates/ グローバルテンプレートファイル</li>
</ol>
<h3><span style="font-size: 14px;line-height: 23px">WEBサーバーの設定</span></h3>
<ul>
<li><strong>httpd.conf</strong> を編集します。(httpd.confのパスは環境により異なります)
<pre class="brush: bash; light: true; title: ; notranslate">$ vi /etc/httpd/conf/httpd.conf</pre>
</li>
</ul>
<ol>
<li>User<br />
<strong>User smi</strong><br />
Linuxユーザーsmiの$HOMEディレクトリをプロジェクトホームにしているので、便宜上ユーザーをsmiに変更します。プロジェクトホームをどこにするかなどPermissionをどう与えるかなど基本設計の部分で適宜決める必要があります。</li>
<li>Listen<br />
Listen は、デフォルトでポート番号 80 が1つ記述されています。<br />
<strong>Listen 80</strong><br />
デフォルトの80番ポートを使うならそのまま何もしません。<br />
80番ポートは、通常のhtmlを表示し、symfonyプロジェクトは 8080番ポートを使うといった場合は、もう一行<br />
<strong>Listen 8080</strong><br />
を追加で記述します。<br />
→この場合、8080ポートに対して Firewall の設定が必要です。</li>
<li>VirtualHost<br />
Apacheのバーチャルホスト機能を使用し、公開用ルートディレクトリ /home/smi/jobeet/web を直接アクセスできるように設定します。</p>
<pre class="brush: bash; light: true; title: ; notranslate">NameVirtualHost *:80
&lt;VirtualHost *:80&gt;
  DocumentRoot &quot;/home/smi/jobeet/web&quot;
  DirectoryIndex index.php
  ServerName centos6:80
  ErrorLog logs/centos6-error_log
  CustomLog logs/centos6-access_log common
  &lt;Directory &quot;/home/smi/jobeet/web&quot;&gt;
    AllowOverride All
    Allow from All

  Alias /sf &quot;/usr/share/pear/data/symfony/web/sf&quot;
  &lt;Directory &quot;/usr/share/pear/data/symfony/web/sf&quot;&gt;
    AllowOverride All
    Allow from All
&lt;/VirtualHost&gt;
</pre>
<p>別のポート番号を使用する場合、80 の部分に別のポート番号を指定します。</li>
</ol>
<ul>
<li>Apache を起動(再起動)します。
<pre class="brush: bash; light: true; title: ; notranslate">$ apachectl start
or
$ apachectl restart
</pre>
</li>
</ul>
<h3><span style="line-height: 23px">ブラウザでの確認（プロジェクト)</span></h3>
<ol>
<li>これまでのタスクで、&#8221;/home/smi/jobeet/web&#8221; に &#8220;index.php&#8221; が作成されていますので、PCブラウザから確認します。<br />
<strong>http://centos6/</strong><br />
→当該環境では、IP:192.168.1.100 のWEBサーバーへの名前解決についてhostsファイルを使用します。 PC hostsファイルに1行追加します。</p>
<pre class="brush: bash; light: true; title: ; notranslate">C:\&gt; notepad %windir%\system32\drivers\etc\hosts</pre>
<pre class="brush: bash; highlight: [19]; title: ; notranslate">
# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
127.0.0.1       localhost
192.168.1.100   centos6</pre>
</li>
<li>「Congratulations! You have successfully created your symfony project.」のメッセージが表示されていればOKです。</li>
</ol>
<p style="padding-left: 60px"><span style="font-size: 14px;line-height: 23px"><a href="http://www.square-mi.com/wp/wp-content/uploads/symfony-create-project.png"><img class="alignnone  wp-image-171" src="http://www.square-mi.com/wp/wp-content/uploads/symfony-create-project.png" alt="" width="340" height="305" /></a></span></p>
<h3> モジュールの作成</h3>
<ol>
<li>モジュール &#8220;category&#8221; を作成する。
<pre class="brush: bash; light: true; title: ; notranslate">$ cd jobeet
$ symfony generate:module frontend category
</pre>
<p>※「<a title="PHP Warning" href="http://www.square-mi.com/wp/217/php-warning/">PHP Warning</a>」</li>
<li>/home/smi/jobeet/apps/frontend/modules/ の下に &#8220;jobeet&#8221; ディレクトリ、更にその下に &#8220;actions&#8221;, &#8220;templates&#8221; ディレクトリが作成されます。<br />
これらのディレクトリには、初期のアクションファイル、テンプレートファイルが作成されます。</p>
<pre class="brush: bash; light: true; title: ; notranslate">$ ls apps/frontend/modules/category/actions/
actions.class.php
$ ls apps/frontend/modules/category/templates/
indexSuccess.php</pre>
</li>
</ol>
<h3>ブラウザでの確認(モジュール)</h3>
<ol>
<li>ここまでのタスクが完了した時点で、symfony デフォルトページが表示されるようになります。　PCブラウザから確認します。<br />
<strong>http://centos6/category/index</strong></li>
<li>「Congratulations! You have successfully created a symfony module.」のメッセージが表示されていればOKです。</li>
</ol>
<p style="padding-left: 60px"><a href="http://www.square-mi.com/wp/wp-content/uploads/symfony-create-module.png"><img class="alignnone  wp-image-169" src="http://www.square-mi.com/wp/wp-content/uploads/symfony-create-module.png" alt="" width="369" height="283" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.square-mi.com/wp/138/php%e3%83%95%e3%83%ac%e3%83%bc%e3%83%a0%e3%83%af%e3%83%bc%e3%82%afsymfony%e3%82%92%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
