0

I have a controller called MCPController. I know this seems to go against Cakephp naming convention but

1) the name "MCPs" with the 's' did not make grammatical sense. So I left it as "singular"..

2) i don't actually have/need a Database table called MCP

This MCPController has an action "dayview" that calls a view called dayview.

In my dayview view I have the following code that creates a form:

echo $this->Form->create('MCP', array('formnovalidate' => true, 'controller'=>'MCP', 'action'=>'merchantonchange'));
echo $this->Form->input('MerchantAssignments', array('label' => 'Merchant Assignments',
                                                    'type' => 'select',
                                                    'options'=>$this->Session->read('Auth.MerchantAssignments'),
                                                    'default' => $this->Session->read('Auth.ActiveMerchant'),
                                                    'onChange' => 'this.form.submit()'));
echo $this->Form->end();

I get an error :

Error: Table m_c_ps for model MCP was not found in datasource default.

The error seems to be coming from the line with the "$this->Form->create" code, because taking away the Form->create seems to take the error away.

It seems to be expecting a table m_c_ps to exist in the database?

The form is meant to submit the new dropdown selection (via onchange event) back to the same Controller.

How can i fix this given that i don't actually have a table called m_c_ps ?

Stacktrace:

CORE\Cake\Model\Model.php line 3498 → Model->setSource(string)
CORE\Cake\Model\Model.php line 1355 → Model->getDataSource()
CORE\Cake\View\Helper\FormHelper.php line 207 → Model->schema()
CORE\Cake\View\Helper\FormHelper.php line 459 → FormHelper->_introspectModel(string, string)
APP\View\Layouts\default.ctp line 191 → FormHelper->create(string, array)
CORE\Cake\View\View.php line 935 → include(string)
CORE\Cake\View\View.php line 897 → View->_evaluate(string, array)
CORE\Cake\View\View.php line 529 → View->_render(string)
CORE\Cake\View\View.php line 474 → View->renderLayout(string, string)
CORE\Cake\Controller\Controller.php line 952 → View->render(null, null)
CORE\Cake\Routing\Dispatcher.php line 192 → Controller->render()
CORE\Cake\Routing\Dispatcher.php line 160 → Dispatcher->_invoke(MCPController, CakeRequest, CakeResponse)
APP\webroot\index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)
2
  • Seems weird that Form->create('MCP') is the one that's causing trouble, because I've named my forms any way imaginable (without models) with no problem... Does the error appears on render? What happens if you comment absolutely everything that's on the controller part and just see what happens with the view part alone? Can you post the controller part for that view? Commented Apr 16, 2014 at 13:40
  • There is nothing much in the controller part for that view. I've edited the post to include the stacktrace. Note it shows the Form->Create being called from default.ctp which is my layout, because i tried calling it from both layout and view with same error. Commented Apr 16, 2014 at 13:51

2 Answers 2

1

Well, when you break from Cake conventions, you get into all sorts of trouble ;) But there is help.

In your controller, you need to define that you're not using a model with the Controller::$uses property. Define it as empty where you have your class property declarations

public $uses = array();

Then cake will know NOT to look for a model. If you don't specify this, Cake defaults kick in and it tries to create a 'default' model called MCP and (per Cake convention) and ergo looks for a table called m_c_ps (also per convention)

Sign up to request clarification or add additional context in comments.

1 Comment

This has also worked... I used var $uses = array() in the controller code. I'm thinking tremendusapps solution should be the proper solution as it is also documented in cakephp doco. book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/… Sudhirs solution works too.
1

Form->create() expects model name as first parameter to it. So if you dont want to use model you could either try passing null or false to model parameter, Like:

echo $this->Form->create(null, array('formnovalidate' => true, 'controller'=>'MCP', 'action'=>'merchantonchange'));

or

echo $this->Form->create(false, array('formnovalidate' => true, 'controller'=>'MCP', 'action'=>'merchantonchange'));

1 Comment

This has worked, I set the first param in Form->Create as false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.