I'm using this plugin with CakePHP --> TwitterBootstrap, everything works like a glow except I can't change the layouts. ie. index, add and such.
I have a model called Cinema and have created this with cake bake and the same thing with Views/Cinemas
This is my controller:
<?php
App::uses('AppController', 'Controller');
/**
* Cinemas Controller
*
*/
class CinemasController extends AppController {
/**
* Layout
*
* #var string
*/
public $layout = 'bootstrap';
/**
* Scaffold
*
* #var mixed
*/
public $scaffold;
}
Have i overridden CakePHPs routes into some special scaffolding template?
By defining public $scaffold; in your controller, you tell Cake that you want to enable Scaffolding mode, which allows you to easily insert/edit/delete some records. The scaffolding mode always uses your "default" layout.
In other words, by defining the public $scaffold; variable, you "overrule" your layout. Scaffolding mode doesn't adopt that setting. Simply remove the public $scaffold; line to get back to your bootstrap layout.
Related
I have a File entity for handle files upload in other entities (news/blog/etc).
I point to it with a OneToOne relation and it works fine. But I would change the upload dir, for each relation entity :
upload/news
upload/blog
The upload path is set in my file entity so i dont know how to automaticaly update the path foreach relations...
do you have an idea on how to do it ?
Thanks
Of course you can do it.
On your file entity side, you can add a uploadDir attribute, and create a setter like this :
private $uploadDir;
public function setUploadDir($uploadDir)
{
if (!$this->uploadDir) {
$this->uploadDir = $uploadDir;
}
}
your comment suggest you use Symfony with Doctrine right ?
So you can edit the classical getUploadDir() method like this:
protected function getUploadDir()
{
return 'uploads/' . $this->uploadDir;
}
In the 'parent' entity you have to update this attribute (when it is created) before persist or update.
(I personally use life cycle callbacks but you can do it manually in your controller)
use Doctrine\ORM\Mapping as ORM;
/**
* News
*
* #ORM\Table(name="News")
* #ORM\HasLifecycleCallbacks
*/
class News
{
//....
/**
* #ORM\OneToOne(targetEntity="File",cascade={"persist","remove"})
*/
private $file;
/**
* #ORM\PrePersist()
* #ORM\PreUpdate()
*/
function setUploadDir()
{
$this->getFile()->setUploadDir('news');
}
// ....
You can also add a constant to make the code cleaner...
I hope it'll help you
I'm totally new to the CakePhp framework, so I'm doing the basic tutorial. So far so good, I built the scaffolding for my models, authentication works fine, but I't a little excessive: I would like to allow one action ('index' for example) to be allowed even for non-authenticated users.
I suspect it must have something with "BeforeFilter()", but any solution I tried hasn't worked - probably because they'for CPHP 2.0, and/or I'm dumb
.
The code is here, though it's not particuolarily interesting since it's the one generated by the scaffolding mechanism.
<?php
namespace App\Controller;
use App\Controller\AppController;
/**
* Frutta Controller
*
* #property \App\Model\Table\FruttaTable $Frutta
*/
class FruttaController extends AppController
{
/**
* Index method
*
* #return void
*/
public function index()
{
$this->set('frutta', $this->paginate($this->Frutta));
$this->set('_serialize', ['frutta']);
}
//cut..
}
Use the following:
function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('index'); //allow index without authentication
}
Reference : http://book.cakephp.org/3.0/en/controllers/components/authentication.html#making-actions-public
I'm writing an installation script for my CakePHP web application. I have a InstallController with 6 actions: step1, step2, step3, etc.
At step1 I'm handling Config/database.php creation. Because this file is empty and no datasource is available I have to set public $uses = false; in the InstallController.
At step2 the Config/database.php file is set so I should be able to make a connection to the datasource. This is also necessary because I want to update some database fields in the following steps.
Is it possible to update the public $uses = false; in every following steps after step1?
I'm using CakePHP version 2.3.5
Have you considered loading the model within the actions? So, something like:
<?php
App::uses('AppController', 'Controller');
class InstallController extends AppController {
public $uses = false;
public function step1() {
}
public function step2() {
$this->loadModel("Install");
$this->Install->callMethod();
}
}
In CakePHP 2.x models are lazy loaded, so as long as your step1 action doesn't try to make use of a model, you can safely declare the models in your controllers $uses property, they are not being constructed until your code actually makes use of them.
However, if for some reason you'd actually need to modify $uses, well then just do it, as mentioned models are lazy loaded, so you can modify $uses whenever you want and then access the models afterwards via magic properties on the controller.
In my project, image need to upload and crop. So, I have taken help from http://bakery.cakephp.org/articles/klagoggle_myopenid_com/2010/08/25/jquery-image-upload-crop
By this instruction I have created file jq_imgcrop.php and with code saved it in app/controllers/components and also created cropimage.php and saved it app/views/helpers
after that I add the component and the helper in my controller where I want to use the cropload.
code given below
App::uses('AppController', 'Controller');
App::uses('BarcodeHelper','Vendor');
/**
* OesUsers Controller
*
* #property OesUser $OesUser
*/
// set the default timezone to use. Available since PHP 5.1
class OesUsersController extends AppController {
var $helpers = array('cropimage');
var $components = array('jq_imgcrop');
After saved, it is giving me a error that is "Missing Component!!"
In this define directory, have I made any mistake?
The article in the link is written in cakephp 1.x.
I'm running into a severe problem, In fact I'm not well understanding recess naming convention for relationship. I personally think it should be more documented with concrete examples. Hopefully, if i get to understand it, I can start to write some examples.Also, if someone has well understand Recess relationship convention well, in case, he can explain it here, it would be great
I have two table, all table names are in the database are the lower case of the model names. All fields names are same to the models' attributes
Post---->Comment(A Post can have several comments)
Model Post:
<?php
/**
* !Database Default
* !Table post
* !HasMany comment, Class:try.models.Comment,Key:postId
*/
class Post extends Model
{
/** !Column PrimaryKey, Integer, AutoIncrement */
public $postId;
/** !Column String */
public $name;
}
?>
Model Comment:
<?php
/**
* !Database Default
* !Table comment
* !BelongsTo post
*/
class Comment extends Model {
/** !Column PrimaryKey, Integer, AutoIncrement */
public $commentId;
/** !Column String */
public $name;
}
?>
However, when I'm doing the following, I'm getting an error
<?php
Library::import('try.models.Post');
Library::import('try.models.Comment');
Library::import('recess.framework.controllers.Controller');
/**
* !RespondsWith Layouts
* !Prefix Views: home/, Routes: /
*/
class TryHomeController extends Controller {
/** !Route GET */
function index()
{
$this->flash = 'Welcome to your new Recess application!';
$Post= new Post(5);
$Comments=$Post->comment();
}
}
?>
However, I'm getting this error
try.models.Comment has not been imported.
Look in your Post model at the Class line
**
* !Database Default
* !Table post
* !HasMany comment, **Class:try.models.Comment**,Key:postId
*/
Here you are including the full classpath, try.models.Comment. You only need to specify Comment as the class to include. Be sure that your file names follow the ClassName.class.php convention.