Add A Textfield In Form With Out Model Class In YII?

Feb 24, 2011

I need to add a text field in YII form in which i am not specify any model class name. But I need to process that value in the action method inside the controller class.


I need to add a text field as

<div class="row">
<input type="text" name="test" id="test" >

I add text field as

<?php echo $form->textField($model['groupModel'],'group_name',array('size'=>60,'maxlength'=>128)); ?>

But i do't want to specify any model name with the new text field..

View 2 Replies


Mvc - Difference Between A Library Class And A Model Class?

so i want to follow the mvc conventions but haven't really got the hang of it. i've got problem understanding the explicit difference between a model and a library class and how they relate to each other.

eg. i want to create classes to add/edit contacts and also adding them to a group. i thought it should be divided into 2 classes: Contact and Group. The first class would create a contact. The other one will add the contact to a group. I thought this dividing would be perfect cause their logic is isolated from each others. Contact doesn't care if Group exists or not. Group doesn't care about how a Contact looks like.

So Contact will have these methods:

$Contact->add($name, $email, $address, $phone) // create an entry in database
$Contact->delete($id) // delete the entry in database
$Contact->edit($id, $name, $email, $address, $phone) // edit the entry in database
And Group:
$Group->createGroup($name) // create a group in database
$Group->delete($id) // delete a group in database
$Group->addContact($groupId, $contactId) // add a contact to a group in database

So these classes apparently work with the database. Does this mean that these are models? Or are they library classes that eg. should be put in SYSTEM/LIBRARIES in CodeIgniter. If it's the latter one, how do a Model in this case looks like using the classes?

And how would a controller look like in this scenario? Would be great if someone could give me the big picture!

View 2 Replies

Utility Class Be A Model Class In A MVC Framework?

Im designing a MVC framework but I dont know where should I put my utility classes. I read somewhere where it said utility classes are Model Classes. Is this line of thinking correct or are they some separate type of class?

View 3 Replies

Pass A Textfield Value To A Pop Form?

How to pass a textfield value to a pop form? I need to pass the value so that the drop down box on the form would autopopulate the items related to that value in the textfield. I'm using PHP.

View 3 Replies

Problem With Pressing Enter On One-textfield Form

I have a mail form, where I would like the users to enter a secret code and
check one checkbox before the form are processed and the values can mailed.
Otherwise stop and display an error. But it won't work. What's wrong with my
nice newbie-code? Here it is:

The form:
<form method="post" action="process.php">
<input name="name" type="text" />
<input name="email" type="text" />
<input name="subject" type="text" />
<textarea name="message" rows="6"></textarea>
<p>Enter secret send-code:</p>
<input name="secret_code" type="text" />
<p>Agree to terms?:</p>
Yes <input name="check[]" type="checkbox" value="yes" />
No <input name="check[]" type="checkbox" value="no" />
<br />
<input type="submit" name="submit" value="Send" /><input type="hidden"
name="do" value="send" /><input type="reset" name="reset" value="Reset" />

Here is process.php:


View 2 Replies

Create A Form Which Have An Input Textfield Used To Filled In The Url's Name?

i have created a form which have an input textfield used to filled in the url's name. eggoogle). the effect that i want to get is when i put the mouse key hover on the text google. the url display on the tool bar is my site's internal address. [URL]......en click the text google. it will go to the google site.the input textfield is used to fill in some url's name. how to get this in php

View 1 Replies

Collecting Form Data Without Knowing Textfield Names?

I have a giant form, an order pad for internal employees, that has hundreds of text fields. The names of the text fields are product codes, the values that are returned are quantities.

Example: <input type = 'text' name='ABC123 Product 1' size='3' maxlength='3'>

I need to collect the data from the order pad and generate an email to the office with the order. How do I parse the incoming form to collect the text field name and value?I am guessing this will be done via $HTTP_POST_VARS but do not know how to go out and get only the field names and values where something has been input by the user.

View 2 Replies

Form Textfield Title In Drupal Does Not Accept Special Characters?

I'm trying to give element of a drupal form using the form_alter hook a title that contains special characters

$form['title'] = array(
'#type' => 'textfield',
'#title' => 'this is my title test',
'#required' => TRUE

that gives me a blank output on the form page using the check_plain() function for the title does not affect the output :s ,still blank I though it's an encoding problem but I checked all my enc settings (database,server,theme template) they are all set to utf-8

View 1 Replies

How To Model A Templating Class

I am writing a basic templating class for my own project. The basic usage is this:

$template = new Template('template_file.php');
$template->assignVariable('pageTitle', 'Home page');
Contents of 'template_file.php':
<?php print $pageTitle; ?>

This is what template class does step by step:

Stores variables in a private array when assignVariable method is called When render method is called, extracts stored variables, includes template file in a ob_start() and ob_end_clean() block. Stores output in a variable with ob_get_contents() and then prints stored output.

I know this is a very simple templating class but works as expected. The question is should I delegate the including the template file to another class? I had this question when I was writing the unit tests for this class. I thought that file system interaction should be encapsulated. What do you think? If you think that it should not, how can I mock including a file in my tests?

Maybe I just pass the contents of the template file to the class like this:

$templateContent = file_get_contents('template_file.php');
$template = new Template($templateContent);

Edit: I decided to encapsulate the input process of template class for the sake of writing better unit tests and encapsulation. But as johannes pointed out, I needed to use eval() for that purpose which seemed not right. Johannes pointed me to the direction of stream wrappers for mocking the including in unit tests. But that inspired a new idea on me. Here is what I am going to do; I will continue to use include() in my template class but this time with stream wrappers. I will pass protocol handler to my template class while initializing it. This way I can create my own stream wrappers for fetching template data from database or using a local variable. Here are the examples:


View 4 Replies

Use Of XML For Model Class And Structuring?

I am currently working on a little application: The structure follows in some way the MVC pattern. For short it has the basic things, Models, Controllers etc. Now I am sitting here and do not know whether :

The SQL database is only managed by a model through methods the programmer gives him like: "Hey we have name record so we need a getName() method".

The model dynamically creates the whole database and methods, using a XML file, with which even a non-programmer can design a database.

And should the model class check every/a single request whether it is a valid request e.g. getName() won't work on the houses_tbl, and if it is not valid it does not perform the query, and sends back an error message instead?

I have absolutely no idea how to handle my model class, which structure it should follow and how much the programmer should have to put into a new model so it works as he wants it to work.

Major points: perfomance (which way saves the most perfomance) KISS (which way is simple enough, so a second team mate can understand my logic) extendability (can I extend the structure)

View 2 Replies

Codeigniter How To Map A Class Sent To A Model

I have a SectorModel with this function:

public function update(Sector $sector) {
$this->db->where('sector_id', $sector->getScetor_id());
return $this->db->update(_SECTOR_, $sector);

There are times that I’ll change only the name of the Sector object:

$Sector = new Sector();
$Sector->setSector_name = 'test';
The generated select looks like:

UPDATE realestate_sector SET sector_name = 'teste', sector_description = NULL It will update but will set all other properties to NULL because it was not set on my object. Right now, I have to fill the whole object before sending it. Is there a way to map the Sector class and update only what was sent on the object?

View 2 Replies

Get The Zend_Application's Database Into A Model Class?

I have a Zend_Framework application, which has a whole bunch of model classes. I need these model classes to be able to access the application's database (naturally).

Currently I've put this in my index.php:

And then $db = Zend_Registry::get('db'); in each of my model classes that require the database.

But this seems like a horrible horrible hack. Am I missing something basic here?

View 4 Replies

Magento - Creating Model In Custom Class?

I'm trying to add some custom filter methods to my magento module. I though it would be simple but I can't figure out why it's not working.

My model which extends the catalog/product class contains this:

public function filterProdType($prod_id)
$this->addAttributeToFilter('attribute_set_id', $prod_id);


I didn't realize error reporting was turned off, after turning it on I get the error:

Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection::filterProdType()

View 1 Replies

Retrieving Data In Symfony Using The Model Class?

Let's say I have a model Ecosystem automatically generated with symfony from my schema.yml. At some point in the code, I would like to retrieve records from the table.I know there are some ways to do this with Doctrine/Propel classes, but, is there a way of doing it with directly the model? I've been thinking in something like this:

$ecosystem = new Ecosystem();
$records = $ecosystem->find(...);

By the way, which is the preferred method to do this kind of things?I've been developing with CakePHP and making queries directly with Doctrine doesn't seem natural to me. What if I decide to change to Propel tomorrow?

View 2 Replies

Adding New Field In Model Class Using Yii Framework?

In table i have column 'description' , which contain description of goods. I want include in CGridView column 'short_description', which will contain first 150 characters.

class Product extends CActiveRecord


View 2 Replies

Unable To Call Set Or Create From With In A Model Class?

I'm working in a CakePHP Model class, writing a function that is supposed to perform a whole bunch of manipulations on the model. I'm trying to follow the skinny controller, fat model idea. However, I don't seem to be able to call any of the model's functions from with in my model. Something hasn't been initialized yet, because I get an SQL error when I do:

Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 681]


It looks as if the table name hasn't been set internally somewhere. My model looks like this:

class Search extends AppModel {
var $name='Search';
var $hasMany = 'SearchResult';[code]....

I know everything the Model needs has already been created works find, because calling that exact same sequence of functions works fine from the Model controller. Like so:

function search($query) {
$this->Search->set('query', $query);

That works fine. So what gives? What's going on here?

View 1 Replies

PHING To Generate Class Model Out Classes?

I wants to generate Class Model of all my classes in code base. I wonder if anyone is aware of anything already available to do that. I wants to do similar to this :[URL] I am not sure if is there anything available for PHP to do along with Phing.

View 1 Replies

MVC Authentication - Create A Separate Auth Class (model)?

I have a social network-esque site with a nice User model that seems to be covering all my bases right now.

I am reworking the code from spaghetti and want to find the best-practice solution for logging in / registering a user. Here are my options (I think):

Create a separate Auth class (model?) that simply searches for a record of a user and returns a new User object if found.Add "login" functionality to the User class that will allow me to log my user in as any User object that I'd like.

Please let me know the cleanest way to go about this, as I am new to good coding practices (admittedly)

View 1 Replies

Zend Framework Calling _partial From A Model Class?

I can call partial method from a view object. However, I need to call it from a model class (which is standalone). I need to render a xhtml piece (with code) and parse the result and it happens inside a model class.

View 2 Replies

One View For Two Models: Use A Base Model Class To Make It Easier?

A website for managing hotels.Another kind of Hotel model has been added over the course of the project, so now they are two.Now the boss wants the list of Hotels to include both kinds of Hotels. was thinking of the following possible solutions:Invent a superclass containing the common properties needed to display in the list of Hotels, and override appropriately.Hack my way in the view. It has one loop now, producing HTML code on the way (obviously). If this works, there will be two loops.The problem I see with approach #1 is this: "Hotel1 extends BaseHotel1", "Hotel2 extends BaseHotel2". So OK, I will create a superclass, then what?The problem with approach #2 is this: I am still far from a "pro" Symfony developer and I am not sure the view in question will have access to more than one model methods at all. Maybe render-partials from another module would workSo, how do I do this? Do you think the problems I listed are easy to solve? Do you see another approachesI

View 2 Replies

Web Form Processing By Means Of A Form Model Description?

often, I get asked to write a small mini application which basically presents a form and verifies certain values and conditions once submitted to the server. Thus, I started to generalize the process.

Now, the app loads a YAML specification of the form and a generalized controller manages its processing: Presents an instructional welcome page, presents the form, receives and validates values. Finally, it hands over the verified result to the persistence layer and informs the user, that his data/request has been saved.

The YAML based approach could eventual lead to a solution, in which the client writes himself a form model - without knowing a programming language. I wonder, if I reinvent the wheel. Does someone know of a standard solution?

View 1 Replies

[Zend Framework] Fetch Data From Another Table Within A Zend_Db Model Class?

I have two tables registries and names.Consequently, I have two model classes.I'm coding a method in registries model and I need to fetch all names in the names table/model.How'd I do it?Should a simple new Names() work?But, is it recommended?

View 2 Replies

Modular Application Zend Framework 1.10 Not See Class In Default Folder Model?

i have next folder structure zf version 1.10



When i in any controller trying $a = new Manufactur() i see Error not find class when i before call use include 'path/to/manufactur.php'all work fine

View 2 Replies

Controllers And Libraries To Work In The Model All Ofthe Database Class In The CI User Guide?

I have two databases I need to connect to, which I can do in the controllers and libraries I have written.For some odd reason (i'm assuming I'm just missing something simple here)I can't get it to work in the model all of the sudden. I have read the database class in the CI user guide.I tried making a reference to $pew when loading pew($this->pew =& $this->load->database('pew', TRUE)to no avail.

PHP Fatal error: Call to a member function query() on a non-object in
/Sites/CI/nyan/application/models/pewpewmodel.php on line 15
Line 15
$this->pew->query('SELECT * FROM ExtractEvent'); //simplified for testing database.php:
$active_group = 'nyan';
$active_record = TRUE;


View 2 Replies

Get Model Class With Magento Retrieve Data Based On A Mysql Field Which Is Not A Primary Key?

I would like to change this snippet to fetch some data from a table, and instead of triggering the primary key(which looks like the default behavior of the load() function), I would like to trigger another field in my request...How can i do that ?

$mytable = Mage::getModel('mytable/mytable')->load($mytable_id)->getData();

View 1 Replies

CakePHP - Access He Form Helper's "current" Model As Supplied To $form->create()

In my CakePHP 1.3 application, I need a form control that is: Comprised of multiple form elements, and Reusable in more than one form. I'd like to avoid code duplication if I can. So, I'm creating an element that outputs my form control, and have hit a roadblock when it comes to populating the control with values on an edit action. Now, when you're using the default field types, CakePHP does this for you, but I need to get information out of $this->data and do it myself in this case. The problem is that $this->data looks like this:

'Model' => array( /* fields from Model */ ),
'AnotherModel' => array( /* fields from AnotherModel */ )

Within my reusable element, I don't know what model my field belongs to. However, I told this information to the Form Helper when I called $form->create() (in the view that includes the element I'm writing), so it seems like it should be able to tell me. And indeed, the API documentation for the FormHelper class tells of a defaultModel property, but sadly, this property is empty. Now, the simple solution is to pass the model in as a parameter. I can do that. But, I'd like to avoid parameter bloat where I can, and it seems like this ought to be possible, but I can't figure out how. Is there a way?

View 2 Replies

Copyrights 2005-15, All rights reserved