How can i pass the post variable to segment url? i can read it from url but i can't set it...
What i have so far : $route['shop/find/(:any)']= "shop/find/$1"; on routes,my find.php on views, and my function `
function find()
{
$this->load->model('shopFront/find');
$this->load->model('currency');
$this->load->model('shopFront/calculate');
$this->load->model('shop/proccess');
$data = $this->commondatashop->general();
$inputSlug = $this->input->post('findSlug');
$data['tofind'] = $inputSlug;
$data['cartInfo'] = $this->shopcart;
$data['Currency'] = $this->currency;
$data['Calculate'] = $this->calculate;
$data['Proccess'] = $this->proccess;
$data['title'] = "1.4.U Shop | Find";
$finder = $this->find;
$data['finderservice'] = $finder;
$data['user_id'] = $this->session->userdata('user_id');
$data['user_name'] = $this->session->userdata('user_name');
$this->load->view('shop/top/topNew',$data);
$this->load->view('shop/content/find',$data);
//footer
$curravailable = $this->calculate->getCurrencies();
if ( $curravailable !== false )
{
$data['currencies'] = $curravailable;
}
else
{
$data['currencies'] = 'none';
}
$this->load->view('shop/footer',$data);
}`
How can i post the variable to the find()function with url segment?
you need to have find accept an argument with a default
function find($i=0) {
//$i is whatever is in the URL or defaults to 0
In your view:
echo form_open('/shop/find');
echo form_input('findSlug','');
echo form_submit('submit', 'Submit');
echo form_close();
Controller:
$data[slug] = $this->input->post('findSlug');
You need to load form helper too
Related
I'm trying to edit and save some articles, but I receive this error : Creating default object from empty value. What's wrong in my code?Because, at edit I have my subject, but and submit I get this error.
My error : https://imgur.com/a/eWGqc5B
Controller
public function update($type, $id)
{
/* print_r(Input::all()); die; */
if($type == "News")
{
$article = \App\News::find($id);
$article->subject = Request::input('subject');
$article->public = Request::input('public');
$article->category_id = Request::input('category_id');
$article->information = Request::input('information');
$article->update();
}
if($type == "Event")
{
$article = \App\Event::find($id);
$article->subject = Request::input('subject');
$comm->comments = Request::input('comments');
$article->public = Request::input('public');
$article->category_id = Request::input('category_id');
$article->event_type_id = Request::input('event_type_id');
$article->country = Request::input('country');
$article->starts = Request::input('starts');
$article->ends = Request::input('ends');
$article->organizer = Request::input('organizer');
$article->address = Request::input('address');
$article->city = Request::input('city');
$article->website = Request::input('website');
$article->email = Request::input('email');
$article->telephone = Request::input('telephone');
$article->information = Request::input('information');
$article->update();
}
return redirect(URL::previous());
Line 669 in ArticleController.php
$article->subject = Request::input('subject');
Here is my editEvent code : https://codepen.io/anon/pen/YodwKO
my articles.blade code : https://codepen.io/anon/pen/jjXWOb
My route:
`
Route::post('admin/article/update/{type?}/{id?}', [ 'as' => 'update.article', 'uses' => 'ArticleController#update']);
`
The variable $comm is not defined. It looks like a typo.
I have the following problems !
I recieve the information from the form
public function crearcomentario ()
{
$blogId = \Request::input('identificador');
$autor = \Request::input('autor');
$correo = \Request::input('correo');
$content = \Request::input('content');
$find = User::where('username','=',$autor)->get();
$buscar = $find->toArray();
$comentarios = new Comentario();
//$comentarios->autor_id = $buscar[0]["id"];
$comentarios->correo = $correo;
$comentarios->articulo_id = $blogId;
$comentarios->contenido = $content;
echo $find;
echo $autor;
//$comentarios->save();
}
The variable $find return the information about user introduce in the form.
My question is how can I compare if the user find is empty [] ? I try to use
if(is_null($find))
but doesn't work.
$find would be a Laravel Collection. You can use the isEmpty() function to check whether it is empty:
if($find->isEmpty()) { ... }
try this,
$find = User::where('username','=',$autor)->get();
if($find) {...}
I'm running a social network and right now my search.php shows results for people, and tags. How can I add an RSS Feed? I own a blog and I wanted to add my RSS Feed to the search so whenever someone searches for a topic it will show up on the search page.
Here's the search.php code:
$feed = new feed();
$feed->db = $db;
$feed->url = $CONF['url'];
if(isset($_SESSION['username']) && isset($_SESSION['password']) || isset($_COOKIE['username']) && isset($_COOKIE['password'])) {
$verify = $loggedIn->verify();
if($verify['username']) {
$feed->user = $verify;
$feed->username = $verify['username'];
$feed->id = $verify['idu'];
if(isset($_GET['tag'])) {
$skin = new skin('shared/top'); $top = '';
$TMPL['theme_url'] = $CONF['theme_url'];
$TMPL['private_message'] = $verify['privacy'];
$TMPL['avatar'] = $verify['image'];
$TMPL['url'] = $CONF['url'];
$top = $skin->make();
}
}
}
$feed->per_page = $settings['perpage'];
$feed->time = $settings['time'];
$feed->censor = $settings['censor'];
$feed->smiles = $settings['smiles'];
$feed->c_per_page = $settings['cperpage'];
$feed->c_start = 0;
$feed->l_per_post = $settings['lperpost'];
$TMPL_old = $TMPL; $TMPL = array();
$skin = new skin('shared/rows'); $rows = '';
if(empty($_GET['filter'])) {
$_GET['filter'] = '';
}
// Allowed types
if(isset($_GET['tag'])) {
// If the $_GET keyword is empty [hashtag]
if($_GET['tag'] == '') {
header("Location: ".$CONF['url']."/index.php?a=welcome");
}
$hashtags = $feed->getHashtags(0, $settings['qperpage'], $_GET['tag'], null);
$TMPL['messages'] = $hashtags[0];
} else {
// If the $_GET keyword is empty [user]
if($_GET['q'] == '') {
header("Location: ".$CONF['url']."/index.php?a=welcome");
}
$TMPL['messages'] = $feed->getSearch(0, $settings['qperpage'], $_GET['q'], $_GET['filter']);
}
$rows = $skin->make();
$skin = new skin('search/sidebar'); $sidebar = '';
if(isset($_GET['tag'])) {
$TMPL['trending'] = $feed->sidebarTrending($_GET['tag'], 10);
} else {
$TMPL['genre'] = $feed->sidebarGender($_GET['filter'], $_GET['q']);
}
$TMPL['ad'] = generateAd($settings['ad6']);
$sidebar = $skin->make();
$TMPL = $TMPL_old; unset($TMPL_old);
$TMPL['top'] = $top;
$TMPL['rows'] = $rows;
$TMPL['sidebar'] = $sidebar;
if(isset($_GET['logout']) == 1) {
$loggedIn->logOut();
header("Location: ".$CONF['url']."/index.php?a=welcome");
}
$TMPL['url'] = $CONF['url'];
if(isset($_GET['tag'])) {
$TMPL['title'] = '#'.$_GET['tag'].' - '.$settings['title'];
} else {
$TMPL['title'] = $LNG['title_search'].' - '.$_GET['q'].' - '.$settings['title'];
}
$skin = new skin('shared/timeline_x');
return $skin->make();
Please help :)
Try this example
<?php
$articles = $pages->find('blog')->children()->visible()->flip()->limit(10);
snippet('feed', array(
'link' => url('blog'),
'items' => $articles,
'descriptionField' => 'text',
'descriptionLength' => 300
));
?>
link:
This is the main link in our feed, which takes the visitor back to our site. In this case we want them to get back to our blog, so we build an url to our blog with the url() helper function.
items:
As items for our feed, we pass the set of $articles we found in the first line. The feed snippet will automatically take care of getting the right info out of those $articles (like title, url, etc.)
descriptionField:
If you want to show a description for each item in your feed, you need to specify a field, which is available in any item and should be used for the description.
descriptionLength:
This is maximum number of characters the description will have. An excerpt is automatically generated by the feed snippet.
I am trying to call a model from my controller, which in turn generates data from a view, saves it as content and returns it to the controller, which then adds it to a template I have.
Whats happening is that $content = $this->load->view('left/profile', $c_data); is printing the data instead of saving it in variable $content
Here is my code:
Controller:
function index($page = '1-Welcome to')
{
if (!$this->tank_auth->is_logged_in()) {
//display non-login page
redirect('/auth/login/');
} else {
//user information
$user['user_id'] = $this->tank_auth->get_user_id();
$user['username'] = $this->tank_auth->get_username();
//general page data
$main['title'] = $this->page_model->make_title(ucfirst($page));
//template data
$template['head'] = $this->load->view('templates/head', $main, TRUE);
//get left content
$c_data['make_profile'] = $this->left_model->make_profile($user);
//combine into one variable
$data['template'] = $template;
$data['page'] = $page;
$data['user'] = $user;
$data['left'] = $c_data;
print_r($data);
$this->load->view('main_template', $data);
}
}
Focus on $c_data['make_profile'] = $this->left_model->make_profile($user);
Here is make_profile
public function make_profile($user)
{
$user_id = $user['user_id'];
$query = $this->db->query(" SELECT location FROM user_profiles AS up
INNER JOIN avatars AS a
ON up.avatar_id = a.id
WHERE user_id='$user_id'");
$c_data['avatar_loc'] = $query->row_array();
$content = $this->load->view('left/profile', $c_data);
$content .= "hello";
return $content;
}
And here is my profile view:
<div id="profile">
<div id='avatar'><img src="<?php echo $avatar_loc['location'] ?>" alt="avatar_user"/></div>
<div id="profile_pop"></div>
</div>
Any idea why it isn't working? Thanks
Return the data from the view as a string:
$this->load->view('left/profile', $c_data, TRUE);
Read here (bottom of the page).
Is this possible if I put my form_helper with array parameter in my smarty template.
this is my method of my controller:
function input($pIntBookId = 0) {
$this->load->model('m_books');
if($this->input->post('mysubmit')){
if($this->input->post('id')){
$this->m_books->entryUpdate();
}else{
$this->m_books->entryInsert();
}
}
$arrData = $this->m_books->general();
if((int)$pIntBookId>0){
$strQuery = $this->m_books->getId($pIntBookId);
$arrData['idxFid']['value'] = $strQuery['book_id'];
$arrData['idxFtitle']['value'] = $strQuery['book_nm'];
$arrData['idxFauthor']['value'] = $strQuery['book_aut'];
$arrData['idxFpublisher']['value'] = $strQuery['book_pub'];
$arrData['idxFyear']['value'] = $strQuery['book_year'];
if($strQuery['book_st']=='yes'){
$arrData['idxFavailable']['checked'] = true;
}else{
$arrData['idxFavailable']['checked'] = false;
}
$arrData['idxFsummary']['value'] = $strQuery['book_ds'];
}
$this->mysmarty->assign('arrData',$arrData);
$this->mysmarty->view('v_booksinput.php');
}
Is this possible..? :
<td>{php} echo form_input($idxFtitle);{/php}</td>
You can write own smarty-function which does what you want.
{function name="my_input" data}
<input name="{data['value']}"></input>
{/function}