Using Fuelphp 1.7 the URLs only seem to work in upper case.
For example the following controller only works on the following url
http://www.example.com/Index/test/
and doesn't work on the following url (which I would expect would work)
http://www.example.com/index/test/
Here is the controller code:
class Controller_Index extends Controller
{
public function action_test()
{
echo 'here';
die();
}
}
I tried setting case_sensitive to false
'routing' => array(
/**
* Whether URI routing is case sensitive or not
*/
'case_sensitive' => false,
);
It looks like the index is being clipped somewhere in a redirect. Other controller names work fine in lower case. See the below from the $_SERVER superglobal. (Routing works based first on PATH_INFO)
["REQUEST_URI"]=>
string(12) "/index/test/"
["SCRIPT_NAME"]=>
string(10) "/index.php"
["PATH_INFO"]=>
string(6) "/test/"
Change
class Controller_Index extends Controller
into
class Controller_index extends Controller
(note the capitalisation).
Related
In config/main.php I have this declared:
'onBeginRequest' => array('Controller', 'reSetUser'),
in protected/components/Controller.php I have this:
class Controller extends CController {
public function reSetUser() {
Yii::app()->request->redirect('/login/index');
}
}
If i commented the reSetUser function, it works, it returns me the content of the view. On the other hand, if want to check smth and DO a REDIRECT, it gives me this:
in the firebug.
WHY? can someone help me ?
I'm writing my first Cake app and trying to set up my first deep association. It's very nearly working but I have a couple of small issues.
So I created a form to add a customer. A customer has many addresses and an address has many contacts. The issue I have is that the Form helper doesn't seem to recognise the contact fields for formatting purposes. However, if I perform a find() in the action the form displays correctly. It's like the model isn't linking until it's used.
Here's the 3 models:
class Customer extends AppModel {
public $hasMany = 'CustomerAddress';
}
class CustomerAddress extends AppModel {
public $belongsTo = 'Customer';
public $hasMany = 'CustomerContact';
}
class CustomerContact extends AppModel {
public $belongsTo = 'CustomerAddress';
}
Until it's submitted, the add action basically does nothing so I won't bother posting that, but here's some extracts from the view:
add.ctp
echo $this->Form->input('CustomerAddress.0.CustomerContact.title', 'options' => array( 'Mr' => 'Mr', 'Miss' => 'Miss', 'Mrs' => 'Mrs', 'Ms' => 'Ms', 'Dr' => 'Dr')))."\n";
echo $this->Form->input('CustomerAddress.0.CustomerContact.first')."\n";
echo $this->Form->input('CustomerAddress.0.CustomerContact.last')."\n";
.....
echo $this->Form->input('CustomerAddress.address1')."\n";
echo $this->Form->input('CustomerAddress.address2')."\n";
.....
echo $this->Form->input('type', array( 'label' => 'Business Customer?'))."\n";
So, the CustomerAddress fields work fine, they are the right type, limited length etc to match the database, but the CustomerContact fields aren't working at all. Likewise, if I submit invalid data, the add action does a saveAll and fails, but the form fields are then displayed correctly.
If I add a find() to the action before the page is displayed, they work fine. It's like the Model isn't being included until it's used.
I'm sure there's probably a simple command to get it to read the models or something but I'm a bit stuck with it.
ok, after much digging, I got this to work by calling ->loadModel on the controller. Since in this case I need all 3 models loaded in virtually every case, I added a beforeFilter to do this every time.
I didn't change the code for any models, but added this to the controller:
CustomerController.php
class CustomerController extends AppController {
public $helpers = array( 'Html', 'Form', 'Humanize');
public function beforeFilter() {
// Load associated models
$this->loadModel( 'CustomerAddress');
$this->loadModel( 'CustomerContact');
}
.....
}
Even though the CustomerContact model is loaded from the Customer model instead of the CustomerAddress model, Cake seems to respect the relationship and load it under CustomerAddress. At first, I tried:
$this->CustomerAddress->loadModel( 'CustomerContact');
but it was failing. Seems to work fine this way.
I am trying to support the use of EITHER GET or POST methods in my REST controller in laravel.
So, I would like to redirect ANY get requests sent to our REST controller to the POST method in the SAME controller instead.
I have tried many things, and now have returned back to basics as follows:
routes.php
Route::resource('user', 'userController');
userController.php
class userController extends \BaseController {
public function index() {
return Redirect::action('userController#store');
}
public function store() {
echo 'yeeha!';
}
}
Performing a POST on the page works and outputs:
yeeha!
Performing a GET on the page produces:
Could not get any response
This seems to be like an error connecting to https://www.test.com/user. The response status was 0.
Check out the W3C XMLHttpRequest Level 2 spec for more details about when this happens.
I have tried many different redirects and none are successful.
The correct way is to do it is to use the routes file and just define it;
Routes.php
Route::get('/user', array ('as' => 'user.index', 'uses' => userController#store))
Route::post('/user', array ('as' => 'user.create', 'uses' => userController#store))
Controller
class userController extends \BaseController {
public function store() {
echo 'yeeha!';
}
}
I have built a form in YII and I need to process an uploaded file. I followed this guide, but I've stumbled upon an issue. CUploadedFile::getInstance always returns null.
Here's what I use. My model:
class AdditionalFieldFile extends CFormModel {
public $uploadedFile;
/**
* #return array validation rules for model attributes.
*/
public function rules() {
return array(
//note you wont need a safe rule here
array('uploadedFile', 'file', 'allowEmpty' => true, 'types' => 'zip,doc,xls,ppt,jpg,gif,png,txt,docx,pptx,xlsx,pdf,csv,bmp'),
);
}
}
And handling the uploaded file in the controller on form submit:
$model = new AdditionalFieldFile();
$model->uploadedFile = CUploadedFile::getInstance($model, 'field_'.$type_field.'['.$id_common.']');
And after that $model->uploadedFile is null for some reason.
Note that $type_field and $id_common come dynamically.
Also, the form has 'enctype'=>'multipart/form-data' so this is not the cause.
Ok, a self-answer follows.
It turns out that I had to use the active file field in the view, using an instance of the class that extends CFormModel as a model.
Solution:
CHtml::activeFileField(new AdditionalFieldFile(), 'field_'.$type_field.'['.$id_common.']');
I want to test that my /login page is working well and rejecting invalid credentials i.e. not redirecting to the user's dashboard and showing an aller message identified here with the .alert HTML class. So I've created a test like this:
class AuthControllerTest extends Zend_Test_PHPUnit_ControllerTestCase {
...
public function testUserFailingLogin() {
$this->request->setPost(array(
'email' => 'wrong#email.com',
'password' => 'wrongpassword',
));
$this->request->setMethod('POST');
$this->dispatch('/login');
$this->assertQuery('.alert');
}
}
My problem is that the assertQuery() method is running against the render of login.phtml view file and is not including my Zend_Layout set up (that's where the .alert's are shown) and thereof, the assertQuery() assertion fails always.
Is there any way to get assert*Query*() assertions evaluating the full response ("layout" + "view"), instead of just the "view" part?
You(I) should use the undocumented outputBody() method.