centos7.2 + Apache2.4 + php7 + cakephp3 + mysql5.6 で管理画面を作ります。 その4
centos7.2 + Apache2.4 + php7 + cakephp3 + mysql5.6 で管理画面を作ります。 その4
cakephpにbootstrapテーマを適用します。メモとして書きます。
"bootstrap無料テーマ"とか検索したら、良さそうなテーマあるので、
今回は”SB Admin 2”ってやつを使います。シンプルで良さそう。
github.com
テーマをダウンロードして、展開する。
/pages/index.htmlをベースに使えそう。
/distと/vendorにjsとcssが格納されている。
cakephpでは/src/Template/Layout/default.ctpがデフォルトレイアウトファイルとして使われる。
/src/Template/Layout/default.ctp
<div class="container clearfix"> <?= $this->fetch('content') ?> </div>
"fetch('content') ?>"で各Actionで指定したテンプレート(index.ctp)が描画される。
”SB Admin 2”のindex.htmlをコードdefault.ctpに貼り付けて、メインエリアに下記を貼り付けたら、
いい感じになった。
<div class="container clearfix"> <?= $this->fetch('content') ?> </div>
ただし、index.htmlをそのまま貼り付け場合は、不要なダッシュボードのウィジェットがあるのでhtmlタグを削除するのと、cssやjsのパスをcakephp(/webroot)用に変更してあげる必要がある。
今回のテーマ以外でも上記の作業をしてあげれば、使えそう。
centos7.2 + Apache2.4 + php7 + cakephp3 + mysql5.6 で管理画面を作ります。 その3
centos7.2 + Apache2.4 + php7 + cakephp3 + mysql5.6 で管理画面を作ります。 その3
TOPページをとりあえず作ります。
MVCモデルのControllerを用意します。
$this->render('index');でレンダリングしたいViewを名前を指定する。
デフォルトではアクション名(index)のView(index.ctp)がレンダリングされる。
今回は明示的に指定している。本来は不要。
src/Controller/IndexController.php
<?php namespace App\Controller; use App\Controller\AppController; class IndexController extends AppController { /** * Index method * * @return \Cake\Http\Response|void */ public function index() { //index.ctpをレンダリング $this->render('index'); } }
次にViewを用意する。ファイル名はControllerで指定したindex.ctp。
とりあえず空のviewを作ります。
src/Template/Index/index.ctp
<?php /** * @var \App\View\AppView $this * @var \App\Model\Entity\User[]|\Cake\Collection\CollectionInterface $users */ ?> <a>index</a>
最後にルーティングの設定を変更します。
"/"でアクセスされた場合はデフォルトではPagesのControllerのdisplayのactionを指定している。
これを"/"でアクセスされた場合はIndexのControllerのindexのactionを呼び出すように変更する。
config/routes.php
routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); ↓変更 $routes->connect('/', ['controller' => 'Index', 'action' => 'index']);
これで"/"アクセスした場合に、index.ctpが表示されます。
centos7.2 + Apache2.4 + php7 + cakephp3 + mysql5.6 で管理画面を作ります。 その2
centos7.2 + Apache2.4 + php7 + cakephp3 + mysql5.6 で管理画面を作ります。 その2
my_appデータベース作成
#mysql接続 rootユーザで前回設定したrootパスワードを入力 mysql -u root -p #データベースを確認 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.01 sec) #my_appデータベースの作成 mysql> CREATE DATABASE my_app; Query OK, 1 row affected (0.00 sec) #データベースを確認 "my_app"が作成されていることを確認 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | my_app | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec)
webrootディレクトリ移動&ドキュメントルートの変更
sudo vi /etc/httpd/conf/httpd.conf 変更 DocumentRoot "/var/www/cake/webroot" -> DocumentRoot "/var/www/cake" 変更(Directoryのパスと.htaccessの設定を無効化) ------------------------------------------------------------ <Directory "/var/www/cake"> AllowOverride All </Directory> ↓ <Directory "/var/www/cake/webroot"> AllowOverride None </Directory> ------------------------------------------------------------ #apache起動 sudo service httpd restart
.htaccessの無効化
cd /var/www/cake ls la sudo vi .htaccess ------------------------------------------------------------ 変更 RewriteEngine on -> RewriteEngine off ------------------------------------------------------------ .htaccessで設定した場合、リクエストがあるたびに.htaccessを探すので、 パフォーマンスは悪くなるらしい。
centos7.2 + Apache2.4 + php7 + cakephp3 + mysql5.6 で管理画面を作ります。 その1
centos7.2 + Apache2.4 + php7.0 + cakephp3 + mysql5.6 で管理画面を作ります。
リポジトリを最新にする
sudo yum update
php7.0インストール
#epelリポジトリ追加 sudo yum install epel-release #remi追加 sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm #php7とパッケージをインストール sudo yum install --enablerepo=remi,remi-php70 php php-devel php-pear php-mbstring php-pdo php-gd php-zip php-xml php-fpm php-mcrypt php-mysqlnd php-pecl-apcu php-pecl-zendopcache php-intl #phpのバージョン確認 php --version PHP 7.0.30 (cli) (built: Apr 24 2018 21:28:23) ( NTS ) #php.ini修正 sudo vi /etc/php.ini ------------------------------------------------------------ date.timezone = 'Asia/Tokyo' に変更 extension=intl.so を87行目に追加 ------------------------------------------------------------
Apache2.4インストール
sudo yum install httpd httpd -v Server version: Apache/2.4.6 (CentOS)
cakephp3インストール
sudo curl -s https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer mkdir /var/www/cake chown xxx:xxx /var/www/cake cd /var/www/cake composer create-project --prefer-dist cakephp/app ./ composer install
apache設定変更
sudo vi /etc/httpd/conf/httpd.conf ------------------------------------------------------------ 変更 DocumentRoot "/var/www/html" -> DocumentRoot "/var/www/cake" 変更 <Directory "/var/www/html"> -> <Directory "/var/www/cake"> 変更 AllowOverride none -> AllowOverride all ------------------------------------------------------------ #apache起動 service httpd start
mysqlインストール
yum -y install wget wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm rpm -Uvh mysql-community-release-el6-5.noarch.rpm yum -y install mysql-community-server mysql --version mysql Ver 14.14 Distrib 5.6.40, for Linux (x86_64) sudo /etc/init.d/mysqld restart mysql_secure_installation vi /etc/my.cnf 下記追加 -------------------------------------------------------------- [client] default-character-set=utf8 [mysqld] skip-character-set-client-handshake character-set-server = utf8 collation-server = utf8_general_ci init-connect = SET NAMES utf8 [mysqldump] default-character-set=utf8 [mysql] default-character-set=utf8 -------------------------------------------------------------- #mysql再起動 /etc/init.d/mysqld restart
cakephpの設定
vi /var/www/html/config/app.php 220行目あたりが'Datasources' = DBの接続設定 (仮) 'username' => 'root', 'password' => 'XXX', 'database' => 'my_app', 'timezone' => '+09:00', vi /var/www/html/config/bootstrap.php ------------------------------------------------------------ date_default_timezone_set('Asia/Tokyo');に変更 ------------------------------------------------------------
ブラウザアクセス
cakeの初期画面が表示される。
Databaseにmy_appデータベースが存在しないため、エラーとなっているが、今回はここまで。
次回は"my_app"データベースの作成とドキュメントルートの変更を行う。
UITableViewCell
完成図はこんな感じ
プロジェクト新規作成 → 「SingleView Application」を選択 → product Nameは「SampleCell」で作成。
初期から存在するView Controllerに「TableView」をドラッグ&ドロップする。
ドロップしたTableVIewをViewControllerの全体に広げる。
TableViewの上にTableViewCellをドラッグ&ドロップする。
「Table View Cell」を選択し、Attributei nspecterの中のidentifierの項目に「Cell」を入力する。
ViewController.swiftを選択する。
下記のようにソースを修正する。
import UIKit // ①修正(UITableViewDataSource, UITableViewDelegate) class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //②追加 //テーブルの行数を返却する func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 10 } //③追加 //テーブルの行ごとのセルを返却する func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = String(indexPath.row) return cell } }
②と③のメソッドはUITableViewDataSourceの必須メソッドなので、記述なしだとエラーになる。
UITableViewDelegateとUITableViewDataSourceプロトコルの処理を行うクラスを、UIViewControllerの継承先のViewContollerに関連づける。
「ViewControllerScene」ツリーの「View Controller」→「View」→「Table View」を選択した状態でControlキーを押しながら、「View Controller」にドラッグ&ドロップする。ポップアップ画面が表示されるので、「dataSource」を選択する。 ドラッグ&ドロップを再度行い、「delegate」を選択する。これで関連付けが完了する。
Xcodeで保存&ビルドを実行。
ios10のローカル通知 〜通知削除
UNUserNotificationCenterを使って複数のローカル通知登録した場合に、
コメントアウト&ビルドした後もコメントアウト前に登録した通知情報が残る&通知される。
mport UIKit import UserNotifications class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let center = UNUserNotificationCenter.current() center.requestAuthorization(options: [.alert, .sound]){ (granted, error)in } //バックグラウンドで60秒ごとに通知登録 let content = UNMutableNotificationContent() content.title = "ローカル通知確認60s" content.body = "ローカル通知確認60s!!!!!!" content.sound = UNNotificationSound.default() let trigger = UNTimeIntervalNotificationTrigger(timeInterval: (60), repeats: true) let requestIdentifier = "60sTrigger" let request = UNNotificationRequest(identifier: requestIdentifier, content: content, trigger: trigger) center.add(request) //下記をコメントアウトしても一度でも登録した場合にコメントアウト後にも通知されてしまう。 //バックグラウンドで70秒ごとに通知登録 //let content70 = UNMutableNotificationContent() //content70.title = "ローカル通知確認70" //content70.body = "ローカル通知確認70!!!!!!" //content70.sound = UNNotificationSound.default() //let trigger70 = UNTimeIntervalNotificationTrigger(timeInterval: (70), repeats: true) //let requestIdentifier70 = "70sTrigger" //let request70 = UNNotificationRequest(identifier: requestIdentifier70, content: content70, trigger: trigger70) //center.add(request70)
そんな時は通知情報を削除するremoveAllPendingNotificationRequestsを実行すると通知前の情報は全て削除される。
identifierを指定して特定の通知のみを削除するremoveDeliveredNotifications(withIdentifiers:)もある。