Yii Framework Forum: view - render only works with full path - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

view - render only works with full path Rate Topic: -----

#1 User is offline   newlinac 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 18-June 17

Posted 18 June 2017 - 08:42 AM

I am a complete novice with Yii2, but have decades of programming in other languages. I have bought "Yii2 By Example" by Fabrizio Caldarelli, and installed a vanilla basic Yii2 system, so I am on 2.0.12 with PHP 7.1.1 running locally on Win 10 Pro. I have got to chapter 2, which is the first use of a view in a "news" controller. There is a corresponding action funtion


localhost/basic/web/index.php?r=news/items-list
...
public function actionItemsList()
{
$newsList = [
[ 'title' => 'First World War', 'date' => '1914-07-28' ],
[ 'title' => 'Second World War', 'date' => '1939-09-01' ],
[ 'title' => 'First man on the moon', 'date' => '1969-07-20' ]
];

// return $this->render(‘itemsList’,['newsList' => $newsList]);
return $this->render('@app/views/news/itemsList.php',['newsList' => $newsList]);
}

I have tried various flavours of the commented out line, but they always throw up this error

PHP Notice – yii\base\ErrorException
Use of undefined constant ‘itemsList’ - assumed '‘itemsList’'

However the one with the full path works fine. I have not changed any of the config of the installaion, but it seems something else is missing.

Can anyone help please?

Thanks
0

#2 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,806
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 18 June 2017 - 05:34 PM

The "single quotes" aren't single quotes.
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

#3 User is offline   alrazi 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,309
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 19 June 2017 - 01:29 AM

sometimes operating systems behave weird with camel case paths, I would recommend go lowercase with dashes or underscores. that could be the problem try change it to lowercase filenames.
0

#4 User is offline   newlinac 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 18-June 17

Posted 19 June 2017 - 10:56 AM

View Posttri, on 18 June 2017 - 05:34 PM, said:

The "single quotes" aren't single quotes.


Well spotted. It is somewhat unfortunate that this code snippet came from the source download for the book!

Thanks for your help
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users