sfBBCodeParserPlugin, problems with partial - php

I use symfony 1.4.8 , and sfBBCodeParserPlugin
It works , but I have problem with partial.
My IndexSuccess
include_partial('post/list', array('voice_posts' => $voice_posts)) ?>
In _list.php
echo $bb_parser->getRawValue()->qparse($voice_post->getDescription());
And I have error
Notice: Undefined variable: bb_parser in...
according to the readme I added in action.class
public function executeIndex(sfWebRequest $request)
{
....
$this->bb_parser = new sfBBCodeParser();
}
In ShowSuccess I do not use partial and all work fine.
ShowSuccess.php
echo $bb_parser->getRawValue()->qparse($voice_post->getDescription())
action.class
public function executeShow(sfWebRequest $request)
{
$this->bb_parser = new sfBBCodeParser();
...
}
p.s Sorry for my bad English

You forget you send to the partial the bb_parser:
include_partial('post/list', array('voice_posts' => $voice_posts, 'bb_parser' => $bb_parser))
Remember that the variables used in partials (unless they're global) must be sent when you're defining it.

Related

Undefined property: update_user::$update_model - codeigniter

I am a noob at both PHP and codeigniter, so please be gentle.
I was messing around with this file and got this error.
Message: Undefined property: update_user::$update_model
Filename: controllers/update_user.php
Fatal error: Call to a member function update_user_id() on null in C:.....update_user.php on line 20
here is my code
<?php
class update_user extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('user_model');
}
function show_user_id() {
$id = $this->uri->segment(3);
$data['users'] = $this->update_model->show_users();
$data['single_user'] = $this->update_model->show_user_id($id);
$this->load->view('update_view', $data);
}
function update_user_id() {
$id= $this->input->post('did');
$data = array(
'userName' => $this->input->post('dname'),
'userPass' => $this->input->post('dpass'),
);
$this->update_model->update_user_id($id,$data);
$this->show_user_id();
}
}
this is line 20
$this->update_model->update_user_id($id,$data);
anybody can give any pointers to what is wrong?
thanks in advance
This line:
$this->update_model->update_user_id($id,$data);
Should be:
$this->user_model->update_user_id($id,$data);
Also, every other place where you have used update_model, it should be changed to user_model.
This is assuming that you have only a user_model and no update_model. That's what your code shows.
The error is indicating the problem clearly. you are using update_model model which you haven't loaded in your update_user Controller. If this is it than load the update_model like this $this->load->model('update_model'); else change the code:
$this->update_model->update_user_id($id,$data);
to
$this->user_model->update_user_id($id,$data);
Also please share your model code if there is any issue.

Can't "get" data in get ajax request using laravel

I just can't retrieve the data in my query string section.
I've used AJAX request throughout my website to implement a wide variety of tasks asynchronously and didn't had an issue of this kind.
Route
Route::get('/mensagem/enviar_mensagem', [ 'as' => 'mensagem.enviar_mensagem', 'uses' => 'MensagemController#enviar_mensagem']);
the testing url:
http://mydomain.com.br/mensagem/enviar_mensagem?para=email#bol.com.br
my action method:
public function enviar_mensagem(Request $request)
{
$para = $request->get('para');
//$para = $_GET['para']; I get an undefined index error
echo $para; //always empty string!
}
You need to use input. Like so:
Also, for testing, return versus echo.
public function enviar_mensagem(Request $request)
{
$para = $request->input('para');
return $para;
}
And to spark my curiosity, what does return $request->all() return?
Well, the provided code seems to be correct. Make sure you use \Illuminate\Http\Request. This code
Route::get('/mensagem/enviar_mensagem', function(\Illuminate\Http\Request $request) {
return $request->para;
// return $request->get('para'); // also works
});
returns email#bol.com.br by request http://your-site.app/mensagem/enviar_mensagem?para=email#bol.com.br
I copy pasted your code and both works:
$para = $request->get('para');
$para = $_GET['para'];
//$para = $_GET['para']; I get an undefined index error
Did you make sure the webserver is properly handling the HTTP request?
https://laravel.com/docs/5.4#web-server-configuration
You can try with below code :
use Request;
class xyzController {
public function enviar_mensagem()
{
$para = Request::all();
echo $para['para'];
}
}
First you will need to change the route to add also this
Route::get('/mensagem/enviar_mensagem/{para}',
[ 'as' => 'mensagem.enviar_mensagem', 'uses' =>
'MensagemController#enviar_mensagem']);
And after that in controller
public function enviar_mensagem($para){
return var_dump($para);
}
Use the route method on the request object to access GET parameters
public function enviar_mensagem(Request $request)
{
$para = $request->route('para');
echo $para;
}

Undefined variable Error Laravel only on Live Server

I am working on a custom Laravel Project.
I am getting following error:
Undefined variable: count_pandding (View: /domains/web4/html/manager/app/views/admin/home.blade.php)
but strange thing is this error does not show in localhost and works perfectly only in life server.
I have tried passing variables in 2 ways:
public function home()
{
$count_pandding = \Postjob::where('approve',0)->get()->count();
$count_disapprove = \Postjob::where('approve',2)->get()->count();
$count_approve = \Postjob::where('approve',1)->get()->count();
$count_expire = \Postjob::where('approve',3)->get()->count();
return View::make('admin.home', compact('count_pandding','count_disapprove','count_approve','count_expire'));
}
and 2nd way
public function home()
{
$data['count_pandding'] = \Postjob::where('approve',0)->get()->count();
$data['count_disapprove'] = \Postjob::where('approve',2)->get()->count();
$data['count_approve'] = \Postjob::where('approve',1)->get()->count();
$data['count_expire'] = \Postjob::where('approve',3)->get()->count();
return View::make('admin.home',$data);
}
None of it works in Life Server! But works perfectly in Localhost.
Please review Larvel Response
The second parameter of make is an array with key value bindings. I find it strange that this is working on your local machine.
Try
return View::make('admin.home', [
'count_pandding' => $count_pandding,
...
]);
Or
return View::make('admin.home')->withCountPannding($count_pannding);
//this becomes $countPannding in your view
Update:
return View::make('admin.home')->with($keyValueArray);
//should also translate into $key inside the view.

PHPUnit and Laravel: Call to undefined method stdClass::isEmpty()

I'm trying to test this controller method.
public function handleCreate()
{
$offer = new Offer();
$offer->key_word = $key_word;
$offer->url = $url;
$offer->save();
return Redirect::action('OffersController#index');
}
Here is the test.
public function testCreate(){
Input::replace($input = array('key_word' => 'foo', 'url' => 'http://bar.com'));
$this->mock->shouldReceive('create')->once()->with($input);
$this->app->instance('Offer', $this->mock);
$this->call('POST', 'create');
$this->assertRedirectedToRoute('/');
}
I'm getting this error when running the test.
PHP Fatal error: Call to undefined method stdClass::isEmpty()
Here is the part of the view that is messing it up.
#if($offers->isEmpty())
<p>No offers found.</p>
#else
...
#endif
I cannot figure out how to add the isEmpty() method to my mock model to get past this error.
I have tried mocking the isEmpty() method with this but it still gave the same error.
$this->mock->shouldReceive('isEmpty')->once()->andReturn(false);
Seems the answer to my question was
$this->mock->shouldReceive('isEmpty')->once()->andReturn(false);
But I'm guessing I had something setup wrong the first time I tried it.

Problems with redeclaring classes when using PHP's class_alias in a functional test

I'm using PHP 5.3's class_alias to help process my Symfony 1.4 (Doctrine) forms. I use a single action to process multiple form pages but using a switch statement to choose a Form Class to use.
public function executeEdit(sfWebRequest $request) {
switch($request->getParameter('page')) {
case 'page-1':
class_alias('MyFormPage1Form', 'FormAlias');
break;
...
}
$this->form = new FormAlias($obj);
}
This works brilliantly when browsing the website, but fails my functional tests, because when a page is loaded more than once, like so:
$browser->info('1 - Edit Form Page 1')->
get('/myforms/edit')->
with('response')->begin()->
isStatusCode(200)->
end()->
get('/myforms/edit')->
with('response')->begin()->
isStatusCode(200)->
end();
I get a 500 response to the second request, with the following error:
last request threw an uncaught exception RuntimeException: PHP sent a warning error at /.../apps/frontend/modules/.../actions/actions.class.php line 225 (Cannot redeclare class FormAlias)
This makes it very hard to test form submissions (which typically post back to themselves).
Presumably this is because Symfony's tester hasn't cleared the throughput in the same way.
Is there a way to 'unalias' or otherwise allow this sort of redeclaration?
As an alternate solution you can assign the name of the class to instantiate to a variable and new that:
public function executeEdit(sfWebRequest $request) {
$formType;
switch($request->getParameter('page')) {
case 'page-1':
$formType = 'MyFormPage1Form';
break;
...
}
$this->form = new $formType();
}
This doesn't use class_alias but keeps the instantiation in a single spot.
I do not know for sure if it is possible, but judging from the Manual, I'd say no. Once the class is aliased, there is no way to reset it or redeclare it with a different name. But then again, why do use the alias at all?
From your code I assume you are doing the aliasing in each additional case block. But if so, you can just as well simply instantiate the form in those blocks, e.g.
public function executeEdit(sfWebRequest $request) {
switch($request->getParameter('page')) {
case 'page-1':
$form = new MyFormPage1Form($obj);
break;
...
}
$this->form = $form;
}
You are hardcoding the class names into the switch/case block anyway when using class_alias. There is no advantage in using it. If you wanted to do it dynamically, you could create an array mapping from 'page' to 'className' and then simply lookup the appropriate class.
public function executeEdit(sfWebRequest $request) {
$mapping = array(
'page-1' => 'MyFormPage1Form',
// more mappings
);
$form = NULL;
$id = $request->getParameter('page');
if(array_key_exists($id, $mapping)) {
$className = $mapping[$id];
$form = new $className($obj);
}
$this->form = $form;
}
This way, you could also put the entire mapping in a config file. Or you could create FormFactory.
public function executeEdit(sfWebRequest $request) {
$this->form = FormFactory::create($request->getParameter('page'), $obj);
}
If you are using the Symfony Components DI Container, you could also get rid of the hard coded factory dependency and just use the service container to get the form. That would be the cleanest approach IMO. Basically, using class_alias just feels inappropriate here to me.
function class_alias_once($class, $alias) {
if (!class_exists($alias)) {
class_alias($class, $alias);
}
}
This doesn't solve the problem itself, but by using this function it is ensured that you don't get the error. Maybe this will suffice for your purpose.

Categories