Welcome Guest, Not a member yet? Register   Sign In
Trying to get started with your book "Codeigniter for Rapid PHP Application Development"
#1

[eluser]dallasray[/eluser]
I have created my first controller by following instructions in your book "Codeigniter for Rapid PHP Application Development". When I test it in my browser at http://localhost/index.php/start/hello/fred - I get an error in the browser that says

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: base
Filename: controllers/start.php
Line Number: 21
Fatal error: Cannot access empty property in /Applications/MAMP/htdocs/cipackt/system/application/controllers/start.php on line 21

I removed that line and get the same error for the variable css

Have I not declared them before the constructor?

-----------
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of start
*
* @author dallasray
*/
class Start extends Controller {
//put your code here

var $base;
var $css;

function Start()
{
parent::Controller();
$this->$base=$this->config->item('base_url');
$this->$css=$this->config->item('css');

}

function hello($name)
{
$data['css'] = $this->css;
$data['base'] = $this->base;
$data['mytitle'] = 'Welcome to Dallas Ray\'s Site';
$data['mytext'] = 'Now we are getting dynamic';
$this->load->view('testview',$data);
}

}
?>
#2

[eluser]kilishan[/eluser]
Welcome to CodeIgniter! Once you get the hang of it, I'm sure you'll love it.

Luckily, this one is a simple fix:

change

Code:
$this->$base=$this->config->item(‘base_url’);
$this->$css=$this->config->item(‘css’);

to

Code:
$this->base=$this->config->item(‘base_url’);
$this->css=$this->config->item(‘css’);

Notice the difference is just removing the dollar sign.

Happy coding!
#3

[eluser]dallasray[/eluser]
Thanx a million. That did it.

But what the heck happened there? I am copying the code verbatim from the book and using the same version of CI as the book refers to.

On another note, thanks for the welcome to CI. I have been developing without frameworks for a long while now... but after a recent large project I realized that it's time to do the right thing ;-)

After I put in your fix, I notice the safe_mailto function provided by the url helper. Tried it out. Fast, Awesome, this is going to be great!!
#4

[eluser]kilishan[/eluser]
Glad it worked!

I would guess it's simply a typo in the book.

Yeah, I took a similar path to yours. CI makes it so much easier to put together a large site.
#5

[eluser]jedd[/eluser]
[quote author="dallasray" date="1259733573"]
But what the heck happened there? I am copying the code verbatim from the book and using the same version of CI as the book refers to.
[/quote]

The author slipped, and the technical reviewer nodded off?

Usually authors or publishers will host a web site showing addenda - might be worth checking that before reading any more.




Theme © iAndrew 2016 - Forum software by © MyBB