This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I've followed the tutorial in these YT videos to build a language switcher and bilingual site in PHP (no framework). When I try to test it in WAMP, however, I get the following error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in C:\wamp\www\skydoll\lang\francais.php on line 6
I have found by searching this site that this is often caused by the line above the reported error line, but being new to PHP I can't seem to find anything wrong with the code.
<?php
$lang = array(
'hello' => 'Bonjour',
'goodbye' => 'Au revoir'
);
?>
Anything looks out of place?
Before I got to this point, however, I got other syntax errors in the file init.php, which is the file calling francais.php. Could the error be coming from there? I'll include the code for that as well in case:
<?php
session_start();
$allowed_lang = array('english', 'francais');
if (isset($_GET['lang']) === true && in_array($_GET['lang'], allowed_lang) === true) {
$_SESSION['lang'] = $_GET['lang'];
} else if (isset($_SESSION['lang']) === false) {
$_SESSION['lang'] = 'francais';
}
include 'lang/' . $_SESSION['lang'] . '.php';
?>
Thank you in advance for your help.
if (isset($_GET['lang']) === true && in_array($_GET['lang'], allowed_lang) === true) {
Should be:
if (isset($_GET['lang']) === true && in_array($_GET['lang'], $allowed_lang) === true) {
you forgot place $ character before allowed_lang
Related
Recently I've been experimenting with EPiServerFind, I'm trying to figure out how wildcard queries are used.
I am encountering the following difficulty:
One of my colleagues has set up a POC with EPiServerFind, sadly this only searches for the entire word. For example: If you search 'applepie' you will find the page but searching 'apple' or 'pie' won't find the page.
I've looked into wildcard queries to solve this, however I get unexpected results when I use them.
Details
Like I've pointed out earlier, whenever I query EPiServerFind I get only full word matches.
var basicSearch = _client.Search<IContent>()
.For(q)
.InFields(x => x.Name, x => x.SearchTitle(), x => x.SearchText())
.InAllField()
.ExcludeContainerPages()
.ExcludeContentFolders()
.ExcludeDeleted()
.GetContentResult()
.Select(CreateSearchHitViewModel)
.Where(x => x != null);
I've used an article of Joel Abrahamsson to help me with the implementation of the wildcard query:
var wildcardSearch = _client.Search<IContent>()
.WildCardQuery(String.Format("*{0}*", q), x => x.Name)
.WildCardQuery(String.Format("*{0}*", q), x => x.SearchTitle())
.WildCardQuery(String.Format("*{0}*", q), x => x.SearchText())
.ExcludeContainerPages()
.ExcludeContentFolders()
.ExcludeDeleted()
.GetContentResult()
.Select(CreateSearchHitViewModel)
.Where(x => x != null);
I've used this blog: http://joelabrahamsson.com/wildcard-queries-with-EPiServer-find/
Sadly I get unexpected results when I use this.
I get a few unrelated results but more of the relevant results are completely ignored.
I have no clue as to where this is failing and I hope someone can tell me.
Thank you in advance.
As posted on EPiServer World it seems like you can do it by:
.For(searchTerm, q =>
{
q.Query = searchTerm + "*";
}).InField(x => x.Name)
And I guess you could add wildcard before the word as well.
In Drupal7 theme Getting Parse error: syntax error, unexpected T_DOUBLE_ARROW in /sites/all/themes/arizona_horizontal/template.php on line 254
function template_node_submitted(&$variables){
return t('By !username on #datetime',
array('!username' => theme('username', $variables['node'], '#datetime' => format_date($variable['node']->created),));
}
Could you please tell me where exactly I am going wrong.
The second double arrow ('#datetime' =>) must be in array(). I don't know what you are trying to do but I guess you wanted to write that:
function template_node_submitted(&$variables){
return t('By !username on #datetime', array(
'!username' => theme('username', $variables['node']),
'#datetime' => format_date($variable['node']->created),
));
}
You should probably consider formatting your code with better indentation, that would allow you to see this kind of syntax errors quickly.
I have read and worked with the other posts about this and it appears the version of Laravel 4 I just downloaded has more changes made to the way the JSON input is handled by a controller.
$input = Input::json()->all(); gives me errors as if I am referring to something that does not exist when I request some part of the payload after doing a PUT request. And without ->all(); I get a symfony error.
Does anyone know how to get good JSON from backbone in Laravel 4's latest version?
Currently, I am doing the long way around to get my data, ie:
$input_title = Input::get('title');
$input_completed = Input::get('completed');
$task = Task::find($id);
$task->title = $input_title;
$task->completed = $input_completed;
$task->save();
Yes, I am doing the tutorial on tutsplus to learn laravel/backbone, so a little noob patience is apreciated.
The error I get when using Input::get(); is:
{"error":{"type":"UnexpectedValueException","message":"The Response content must be a string or object implementing __toString(), \"array\" given.","file":"/Users/brentlawson23/Sites/laravel4App/bootstrap/compiled.php","line":16858}}
I really want to get the Laravel-specific answer instead of using straight php to stringify the payload.
I get same error using just Input::json();
For the current beta of Laravel 4, Input::json(); is not getting a stringified version of the request payload that can be used to create a new row in a table, nor does Input::json()->all(); (hoping to play nice with the ParameterBag from symfony). I have tried json_encode among other hacks and basically every step of the way in this tut, I hit some brick wall. Anyone have a suggestion based on what I have presented here?
Today I got this when simply trying to echo the result of $input = Input::json(); :
{"error":{"type":"ErrorException","message":"Catchable Fatal Error: Object of class Symfony\Component\HttpFoundation\ParameterBag could not be converted to string in /Users/brentlawson23/Sites/laravel4App/app/controllers/TasksController.php line 45","file":"/Users/brentlawson23/Sites/laravel4App/app/controllers/TasksController.php","line":45}}
Yes, I have studied the Symfony API.
I had a similar problem. Input from Backbone is converted to array in Laravel. On tutsplus, Jeffrey Way is using object. So I was trying to do this (like in tutorial):
return $input->title // using object,but got an error.
If I change that line to:
return $input["title"] // everything works fine with array.
I'm also working through the Backbone tutorial on tuts+. If I'm right in assuming are you stuck on the Creating New Contacts section? Below is how I got it to work for me, in ContactController.php:
public function store()
{
$input = Input::all();
Contact::create(array(
'first_name' => $input['first_name'],
'last_name' => $input['last_name'],
'email_address' => $input['email_address'],
'description' => $input['description']
));
}
And then also needed to update app/models/Contact.php with the below:
class Contact extends Eloquent {
protected $fillable = array('first_name', 'last_name', 'email_address', 'description');
}
That should get it working for you and insert the contact into the database. If I've misread let me know and I can have another look.
Cheers,
Sean
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am working in extjs4 mvc.I am getting stuck at a point where I want to handle event when tab panels tab going to changed.I am using MVC structure in extjs4.
I am tried with tab change event but it never get fired when tab is changed.please give me some advise how to handle such condition...
here is my some code:--
1) my view file :---
Ext.define('am.view.center.centerTab',{
extend:'Ext.tab.Panel',
id:'centerTabId',
frame:true,
flex:1,
alias:'widget.CenterTab',
minTabWidth: 200,
border: 0,
style: {
borderColor: 'white',
//borderStyle: 'solid'
},
items:[
{
title:'Tab1',
},
{
title:'Tab2',
},
{
title:'Tab3'
}
]//end of items
});// End of login class
2) And here is my controller file some code :---
------
'CenterTab':
{
tabchange:this.tabChaged1
}
}); //end of control
},//end of init function
tabChanged1:function()
{
console.log("tab changed");
},
My requirement is whenever tab is chaged then the tabchange event get handled and particular function is called...
Please give me some advise...
You have misspelled the function name in your controller.
tabchange: this.tabChaged1 should be tabchange: this.tabChanged1
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I Want to separate the database functionality and logic part by having the database operations in the model and the logic part in the controller. Earlier I had all the code in the action part of the controller itself. I have tried something, but it doesn't work.
This is what I had earlier:
/* Controller */
function insertFormName(){
$formname=$_POST['formname'];
$ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1");
$newid=$ret[0]['forms']['id'];
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
}
And now I changed it a bit, which doesn't work:
/* Controller */
function insertformname()
{
$this->data['Form']['formname']=$this->params['form']['formname'];
$this->Form->save($this->data);
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
}
/* Model */
function save($data)
{
$ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1");
$newid=$ret[0]['forms']['id'];
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
return $newid;
}
EDIT:
I have tried it another way.. Have the entire functionality in the model and just call that function from the controller.Is this method correct?
/* Model */
function saveFormName($data)
{
$this->formname=$data[$this->name]['formname'];
$ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1");
$newid=$ret[0]['forms']['id'];
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
}
/* controller */
function insertformname()
{
$this->data['Form']['formname']=$this->params['form']['formname'];
$this->Form->saveFormName($this->data);
}
It looks like you should probably revisit the Cake book (book.cakephp.org) and redo the lessons. If you setup your form correctly, you shouldn't have to manually assign $_POST['formname'] to $this->data. Try setting the field names in your form (in the HTML) to data[ModelName][FieldName].
Next:
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
Why are you updating data right after you saved it? Where do the $newid and $formname variables come from? You have them defined in the Model::save, but not in the controller.
This seems like you're trying to fight with the Cake automagic stuff too much. Perhaps you should repost your question, but please spell out your high level description rather than just a "why doesn't this work?" It looks to me like this could be simplified a ton, but, again, I'm not quite sure what your objectives are.
Respectfully,
Travis