Following from this tutorial..
http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-6-login/
I have successfully implemented and created/logged in users..
I have now added an additional input for the signup form;
signup_form.php
<?php echo form_input('sport', set_value('sport', 'sport?)')); ?>
In the logged in area I would like it to display the users data for 'sport'
logged_in_area
I like <?php echo $this->session->userdata('sport'); ?>
In membership_model I have also added
'sport' => $this->input->post('sport'), in function create_member()
The data inserts into the database correctly! :)
It is just when they are logged in it doesn't pull that user information from the 'sport' column. What have I done wrong? (I have this eerie feeling it's the echo in the logged_in_area)
Thanks!
You have to manually set the value for $this->session->userdata('sport');
I think it is suited for you to add it with with something like
$this->session->set_userdata('sport', $this->input->post('sport') );
in
function create_member()
just after doing the insert into DB
Related
I'm new to yii and I don't understand the extensions much
but I used this extension called jmultiselect2side because I'm trying to make a site where users could reserve stuff like apparatuses in the lab
Anyway, I need a code that would get the Selected Items and then display them in another page for viewing purposes
I haven't put anything in the controller but the name of my controller and model is Apparatus
Here is my view:
<?php
$model= Apparatus::model()->findByAttributes(array('ApparatusCode'=>'1'));
// complete user list to be shown at multiselect order by ApparatusCode
$Apparatus= Apparatus::model()->findAll(
array('order' => 'ApparatusCode'));
?>
<center>
<?php
$this- >widget('application.extensions.jmultiselect2side.Jmultiselect2side',array(
'model'=>$model,
'attribute'=>'ApparatusName', //selected items
'labelsx'=>'Available',
'labeldx'=>'Selected',
'moveOptions'=>false,
'autoSort'=>'true',
'search'=>'Search:',
'list'=>CHtml::listData( // available items
$Apparatus,
'ApparatusCode',
'ApparatusName'),
));
?>
please help as soon as possible :/
put all above elements in a form. Set action for the form. Submit the form then the action in which you are handling this submit request, you can write there
if(isset($_POST))
{
foreach($_POST['Apparatus']['ApparatusName'] as $name)
{
do what ever you want
}
}
$name will represent the each selected item
i work on a registration page in php mysql with yii. i created a registration form and create a auto increment registration number from table student_info in column student_id.when we register any student then it auto assign a registration number .but now i use registration form with above code ,which show a text box , but i want display registration number on that place.my code is ...
<div class="row">
<div class="row-left">
<?php echo $form->labelEx($info,'student_id'); ?>
<?php echo $form->textField($info,'student_id'); ?>
<span class="status"> </span>
</div>
on the place of textfield , what i use , by which it display my auto incement registration number. i am new please help me ?please anyone
Put this code into your model:
public function init() {
if ($this->isNewRecord) {
$this->student_id = $this->generate_code();
}
}
$this->generate_code() - this is your function to generate the registration number :)
Then in your view-template use something like this:
<? echo $info->student_id; ?>
Since the user registration number is a very important one and you probably need it all the time, I would recommend to store it at session when the user login. To do so, you only need the following line at your login component:
$this->setState('registration_number', $user->student_id);
Replace "$user" with the model you use to login.
Then, if you need to display this number just add:
echo Yii::app()->user->registration_number
in the place you want it to be displayed.
been looking for a solution to add a feature for "Custom Columns"... Meaning, I present a list of columns that I can show the user and he selects the ones he wants to see and after the selection the table is updated and add/removes the needed columns.
Didn't find anything on Google (perhaps it has a different name than what I was looking for...)
Anyone has an Idea on how it can be accomplished?
Thanks in advance!
This is not a complete sample, but can give you some clues on how to implement it. You've to define some kind of form to collect the data about how your grid has to be rendered. I recommend you to create a CFormModel class if there are more than 3 input fields. Create a view file with the form and a div or renderPartial of a file containing a grid:
$form = $this->beginWidget('CActiveFormExt');
echo $form->errorSummary($model);
echo $form->labelEx($model,'column1');
echo $form->dropDownList($model
echo $form->error($model,'column1');
echo CHtml::ajaxSubmitButton('UpdateGrid',array('controller/grid'),
array('update'=>'#grid'),
$this->endWidget();
// you can render the 'default options' before any ajax update
$this->renderPartial('_grid',array($customColumns=>array('id','name'),'dataProvider'=>$dataProvider));
In the _grid.php view file:
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'grid',
'dataProvider'=>$dataProvider,
'columns' => $customColumns;
));
In the controller:
function actionGrid(){
// recover the form data, and build the custom columns array
$customColumns = array();
$customColumns[] = '.....';
$dataProvider = ...;
$this->renderPartial('_formTrabajo', array('customColumns' => $idSiniestro, 'dataProvider' => $dataProvider'), false);
}
When you click the ajaxSubmitButton, the form is sent to the url specified through ajax, and the reply from the controller must contain the renderPartial of the view containing the grid, so the jQuery call can replace the html correctly. You must pass an array from your controller to the partial view of the grid, with the custom list of columns you want to display.
I have built a CakePHP app that allows a user to create posts and add tags (topics) to them. The structure of the database and associations can be seen here: Setting up contains for a join table in CakePHP
I have managed to successfully pull the data out using Contain via the join table. But now I'm trying to build the part where a user enters a topic and then save it BOTH in the Topic Table and the Topic_post table.
I have the following code my add new post method:
if ($this->request->is('post'))
{
//$this->Post->create();
if ($this->Post->save($this->request->data))
{
// Save extra data
$this->Post->saveField('user_id', $this->Auth->user('id'));
$this->Post->saveField('datetime', date('Y-m-d H:i:s'));
$this->Post->saveField('modified', date('Y-m-d H:i:s'));
$this->Post->saveField('status', 1);
// Build slug
$post_title = Sanitize::html($this->request->data['Post']['title'], array('remove'=>true, 'quotes' => ENT_NOQUOTES));
$post_title = String::truncate($post_title, 50, array('exact'=>false,'html'=>false,'ending'=>''));
$this->Post->saveField('slug', Inflector::slug($post_title));
// Redirect the user to the newly created post (pass the slug for performance)
$this->redirect(array('controller'=>'posts','action'=>'view','id'=>Tiny::toTiny($this->Post->id),'slug'=>$this->Post->slug));
}
else
{
$this->Session->setFlash('Server broke!');
}
}
So what I need to do now is save the related Topic data which is typed in here in the view:
<?php echo $this->Form->create(); ?>
<?php echo $this->Form->input('Post.title'); ?>
<?php echo $this->Form->input('Post.content', array('type'=>'textarea','label'=>false)); ?>
<?php echo $this->Form->input('Topic.title', array('type'=>'textarea','label'=>'Topics')); ?>
<button type="submit" class="orangeButton small">Create</button>
<?php echo $this->Form->end(); ?>
I have looked at the CakePHP docs and it seems something like saveAll is what I need? But I'm confused as I'm not 100% sure how to use it also it's important to note that a user can save more than one topic to the database and the topics themselves are all unique so for example you can't create a topic that already exists it would instead just use the existing id for the linker.
Can anyone help? As I feel this is rather complex...
You could do something like:
$this->Post->saveAll($this->data, array('validate'=>'first'));
The use of array('validate'=>'first'); ensures that both of our models are validated before saving. Did you mean something like that.
Hope it helps
I’m trying to implement a simple search into an application, but not sure of the best way to handle this. My database contains a Listings object which includes City field. I want to create a search form where the user inputs a city into a text field and gets all of the Listings for that city on the next page. I don’t want to perform a full-text search, just the query on that City field.
Also, on the results page, I’d like to store the query in POST and can’t figure out the best way to do this.
What is the best way to approach this in the controller?
Well your view would look something like this
$this->Form->Create('Listing', array('action'=>'search'));
$this->Form->input('city', array('default'=>$city));
$this->Form->end();
if (isset($listings)) {
//code to display listings
}
This view would create the correct form. And your controller needs to get that value
function search() {
$city = '';
if (!empty($this->data)) {
$city = $this->data['Listing']['city'];
$opts = array(
'conditions' => array('Listing.city' => $city)
);
$listings = $this->Listing->find('all', $opts);
$this->set('listings', $listings);
}
$this->set('city', $city); // so the keyword is saved. Can also get it via $this->data
}
This code should give you an idea on how to do this.
This is a great tutorial with a CakePHP search plugin tutorial. You can download the full working code as well from github (w/ MySQL dump).
View:
<?php echo $this->Form->create()
echo $this->Form->input('search');
?>
<input name="data[Product][word]" />
controller:
<?php
$result = $this->Product->find('all',array(
'conditions'=>array(
'OR'=>array(
array('name LIKE'=>'%'.$word.'%'),
array('description LIKE'=>'%'.$word.'%')))));
$this->set(compact('result'));
?>