Scaffolding with images and users managment

Hello folks,

I am new to Yii, and I would like build a sample CMS using Yii, and I am NOT sure Yii will help me in that or not. I need your guidance:

I wanna post products in the index page with two pictures about the product.

I wanna some users able posts products.

I wanna control panel for administrator to CRUD (users, posts, log-in, … etc) whole system. "Just for Admin"

I wanna control panel for users for CRUD to manage posts as well the images for each post.

I wanna show each product to the visitors with two images or picture and other information.

I wanna my users search about keyword in posts title to update or delete.

I wanna my visors search about keyword in posts title.

I wanna use pagination in my posts.

I mean by users whom they have access to manage the posts with some rolls which I create them via admin account NOT via registrations system.

Could you please advice me which helper or modules I use?

How many helpers we have in Yii?

Is their any book for Yii except documentation?

Thanks…

I would suggest you to take a look at the blog tutorial. Most of the things you wanna do is made in this application.

Thanks What about upload images more than two for each post?

Uploading multiple files is same as here http://www.yiiframework.com/doc/cookbook/2/ except handler code. For multiple files it should be:




if($model->save()){

    foreach($model->image as $file){

        $file->saveAs('path/to/localFile');

    }

}



Thank you Yii, but …

How I can display the image from DB?

How I can allow my visitors search about item via keyword?

Display an image from DB (if you’ve saved a path to your image in the database):


<img src="<?php echo $model->pathToImage; ?>" />

Allow visitors to search by keyword:

[list=1]

[*]Create a search form with a text box and renderPartial it.

[*]On post get the data from the text box (similar to create and update operations) in your controller.

[*]Redirect to a search page passing the search terms in the url.

[*]In the search action of a controller you redirected to, build a query that looks at keywords in the database.

[*]Send the results to a view.

[/list]

Assuming you have a keyword field in database and you passed a ‘searchTermFromUrl’ (be sure to check it too):


$criteria = new CDbCriteria

$criteria->condition = "keyword LIKE :keyword";

$criteria->params = array(':keyword'=>$_GET['searchTermFromUrl']);



Where I should use search section or I should add it?


$criteria = new CDbCriteria

$criteria->condition = "keyword LIKE :keyword";

$criteria->params = array(':keyword'=>$_GET['searchTermFromUrl']);



[/quote]

Yii The I idea I am talking about in this link: http://www.yiiframework.com/forum/index.php?/topic/8005-image-upload-insertread-from-db

Could you please check?

Ill try and break down the images bit for you, bear in mind I am a noob still, hopefully someone will correct me if any of this is wrong :)

adding images to the blog demo -

  1. Create a table in your database to hold the image data,

see protected/data/schema.mysql.sql for examples of how to do this and correctly add the relationship to the Post table.

  1. Use yiic tool to ‘model’ and ‘crud’ your new table,

see blog tutorial for examples.

  1. Adjust the model to your needs, you might need to change the rules() and relations().

  2. Adjust your views to show the photos.

  3. Write an upload action in the controller of your new model and create associated view file(s).

For details of implementing this, have a look at how comments are implemented in the blogdemo.

You do virtually the same for images as is done for comments, the relationships are the same.

The difference is the upload, do the upload as you normally would, if it is successful save the data in the db like this (these are example attributes, yours may differ) -


$model = new ModelName;

$model->file_name = $file_name;

$model->description = $description;

...etc

$model->save();

Study the blog demo, it can really teach you a lot about yii.

If you struggle with the tutorial, just install the completed code from yii download and start playing with it.

Hope that helps.