Find us on facebook

Apr 27, 2015

Disabling errors

In plesk panel
error_reporting -> enter custom value->E_ALL & ~E_NOTICE | E_STRICT

E_NOTICE - undefined variable warning
E_STRICT - Calling non-static methods statically generates an E_STRICT level warning.

Set default controller in yii1

config/main.php

'defaultController' => 'newcontrollername',

Or

framework/web/CWebApplication.php

public $defaultController

Laravel5 - Lesson 1

update route.php

Route::get('about', 'PagesController@about');

Browser access URL -> http://localhost/laravel/BATransfer/public/about

Create PagesController

In CLI type

D:\wamp\www\laravel\BATransfer>php artisan make:controller PagesController --plain

app/Http/Controllers/PagesController.php

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Repositories\UserRepository;

class PagesController extends Controller {

public function about(UserRepository $user_gestion){
$users = $user_gestion->index();
return view('pages.about')->with("allUsers", $users);
}

}

app/Models/User

<?php namespace App\Models;
etc....

Create repository

app/Repositories/UserRepository

<?php namespace App\Repositories;
use App\Models\User;

class UserRepository extends BaseRepository {

/**
* Create a new CommentRepository instance.
*
* @param  App\Models\Comment $comment
* @return void
*/
public function __construct(User $user)
{
$this->model = $user;
}


/**
* Get comments collection.
*
* @param  int  $n
* @return Illuminate\Support\Collection
*/
public function index()
{
return $this->model->all();


}
}

resources/views/pages/about.blade.php

<table>
<tr>
<td>ID</td>
<td>Name</td>
</tr>

@foreach($allUsers as $usr)

<tr>
<td>{{ $usr->id }}</td>
<td>{{ $usr->name }}</td>
</tr>

@endforeach
</table>





Apr 26, 2015

CodeIgniter3 - View folder structure

Commonly used files like header.php, footer.php, menu.php should be placed under views/templates.
Within any other view you can use these files following way.
<?php $this->load->view('templates/top'); ?>
<?php $this->load->view('templates/menu'); ?>

Or In the controller you can use them according to their placement.
$this->load->helper('url');
$this->load->library('AssetLoad');
$this->assetload->queue();
$this->load->view('templates/top');
$this->load->view('templates/menu');
$this->load->view('templates/main');
$this->load->view('templates/footer');

CodeIgniter - Assets


  • Place AssetLoad.php file in the folder application/libraries
  • Create folder called assets in root. (Same level as application and system folders)
  • Within assets folder, following structure should be there.

  • Within assets.ini file you can include following coding

; Asset loader manifest file

    [defaults]
      css[] = "http://127.0.0.5/CI/BATransfer/assets/css/site.css"
        css[] = "http://127.0.0.5/CI/BATransfer/assets/css/main.css"
          js[]  = "http://127.0.0.5/CI/BATransfer/assets/js/html5shiv.min.js"


          Within controller action you can use this library following way.

          $this->load->library('AssetLoad');
          $this->assetload->queue();





          Composer

          Update

          To update all packages

          php composer.phar update

          To update specific packages

          php composer.phar update laravel/framework laravelcollective/html

          To install current dependencies on composer.json(read this file and install) into vendor folder

          php composer.phar install

          Using laravelcollective/html Package in laravel 5

          Add following code to composer.json
          "require": {
          "laravelcollective/html": "5.0.*"
          },

          Install composer into project folder

          In CLI type following command and hit enter

          php composer.phar update laravelcollective/html

          In config/app.php add following

          'providers' => [
              // ...
              'Collective\Html\HtmlServiceProvider',
              // ...
            ],

          'aliases' => [
              // ...
                'Form' => 'Collective\Html\FormFacade',
                'Html' => 'Collective\Html\HtmlFacade',
              // ...
            ],


          [PDOException] SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin g password: YES) - Error

          [PDOException]
            SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin
            g password: YES)

          If above error comes when you run D:\wamp\www\laravel\BATransfer>php artisan migrate
          command, That means you have not configured .env file at root directory. There you need to set

          DB_HOST=localhost
          DB_DATABASE=laravel
          DB_USERNAME=root
          DB_PASSWORD=

          and save it. Then run the above command in CLI. Tables will be created.

          Installing Composer And Installing Laravel 5 (Method 2)

          Download composer to any location you want. You can use following command.

          D:\wamp\www>php -r "readfile('https://getcomposer.org/installer');" | php -- --i
          nstall-dir=composer

          Composer is a directory under www folder. We are going to install composer into that directory.

          Following screenshot will give you more detailed idea.


          After doing this process you will see that you have composer.phar inside the composer folder.

          To install laravel use the following command and hit enter.

          D:\wamp\www\composer>php composer.phar create-project laravel/laravel D:/wamp/www/laravel

          /BATransfer123 --prefer-dist

          Following screenshot will provide more details.


          You are Done. :D

          Installing Composer And Installing Laravel 5

          Installing Composer

          Before you install you need to enable php_openssl in php.ini file. Normally if you enable this on WAMP server,


          It will uncomment php_openssl in D:/wamp/bin/apache/apache2.2.22/bin/php.ini file. But we need to uncomment D:/wamp/bin/php/php5.4.3/php.ini file to install composer. So manually uncomment the line extension=php_openssl.dll

          Then;

          You can download composer for windows from following link
          https://getcomposer.org/download/
          Under Windows Installer click on Composer-Setup.exe to download and then run.

          Or you can use following command in CLI
          php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

          To run php command under any folder in CLI you need to set environment variable. (PHP exe file path)
          Eg: D:\wamp\bin\php\php5.4.3

          Then restart the computer and open cmd, Then just type php and check.

          C:\>php (If no error message displays, then your environment variable has set.

          To check whether composer installed correctly you can type just "composer" and hit enter.(You need to go to composer installed folder)

          Detailed screenshot shown below.


          Installing Laravel 5

          Now you have installed composer. Now create folder called laravel (Or any name) under www root folder and in cmd go to the location you have installed the composer and type following command and hit enter. It will create laravel 5 project called BATransfer (Instead this name you can use any name you prefer for your project)

          C:\ProgramData\ComposerSetup\bin>composer create-project laravel/laravel D:/wamp
          /www/laravel/BATransfer --prefer-dist

          You can see detailed screenshot below.


          After you install laravel successfully, You can see following folder structure under your directory.


          You can access your laravel home page through following URL in localhost.

          http://localhost/laravel/BATransfer/public/

          That's all :D