All posts tagged view

Cakephp: Creating and Sending Parameters Between Controller and View

Cakephp Step By Step Tutorial: We still wok with our first application at cakephp. But we will build controller and view better. Create parameters in controller and send it to view. It will make our application more flexible.

Create a new file books_controller.php within D:\xampp\htdocs\cakephp\app\controllers. Overwrite become like this:

<?php
    class BooksController extends AppController {
		
		var $Books = 'Books';
		var $uses=null;


       function index() {
		   
          $this->set('page_heading', 'Packt Book Store');       
          $book  = array (
                   'book_title'   => 'Object Oriented Programming  
                                                        with PHP5',
                   'author'     => 'Hasin Hayder',
                   'isbn'        => '1847192564',
                   'release_date' => 'December 2007'
                  );
		  
          $this->set($book);       
          $this->pageTitle = 'Welcome to the Packt Book Store!';
       }
    }
?>


Now create a folder books in side D:\xampp\htdocs\cakephp\app\views
And inside books create a file index.ctp. Rewrite with following code:

 <h2><?php echo $page_heading; ?></h2>
    <dl>
    <lh><?php echo $book_title; ?></lh>
    <dt>Author:</dt><dd><?php echo $author; ?></dd>
    <dt>ISBN:</dt><dd><?php echo $isbn; ?></dd>
    <dt>Release Date:</dt><dd><?php echo $release_date; ?></dd>
    </dl>

Point your browser to http://localhost:85/cakephp/books.

CodeIgniter: Getting Parameters From GET

CodeIgniter Step By Step Tutorial: If previous post we learn how to send parameter to view, now, we will learn how to get parameter from GET. As we know, we can see this parameter from Url. Example: http://localhost/index.php?frstname=Arifur. Clear, we can get parameter name. How about in CodeIgniter?

Ok, we learn by doing. Open again your site.php within CodeIgniter/system/application/controller. Rewrite with following code:

<?php
class Site extends Controller{
	
	function Site(){

	parent::Controller();

	}

	function get_name($firstname =  '',$lastname=''){

	$data['name'] = $firstname. ' ' .$lastname ;


	$this->load->view('site_view',$data);	
	}

}
?>

Continue reading →