-
Hiển thị 76-100 của 256 tin nhắn. Mạch tin nhắnĐã gửi cách đây 5457 ngàyĐã gửi cách đây 5457 ngàyĐã gửi cách đây 5457 ngàyĐã gửi cách đây 5457 ngàyĐã gửi cách đây 5457 ngàyĐã gửi cách đây 5458 ngàyĐã gửi cách đây 5459 ngàyĐã gửi cách đây 5459 ngày
Hi Taku giaaa, ta ngu ngon, sang nay ta van yeu doi...vi mat troi van moc o huong dong...va lan o huong tay!! ta thich ngam troi mua tu cua so, nhung ta cung ghet mua lam ta uot lanh, Kun lam viec di nhe, coa ta giam sat roai...hem duoc nampa lung tung doi....hu...keke
Đã gửi cách đây 5460 ngàyĐã gửi cách đây 5461 ngàya. Create the user/login action In the user/actions/action.class.php file (under the new askeet/apps/frontend/modules/ directory), add the following login action: public function executeLogin() {
$this->getRequest()->setAttribute('referer', $this->getRequest()->getReferer()); return sfView::SUCCESS;
} The return sfView::SUCCESS passes the result of the action to the loginSuccess.php template. This statement is implied in actions that don't contain a return statement, that's why the default template of an action is called actionnameSuccess.php.
Đã gửi cách đây 5461 ngàyChappter 05: Form and Pager 1. Login Form Give access to a login form from every page of the application. Open the global layout askeet/apps/frontend/templates/layout.php and add in the following line before the link to about:
- <?php echo link_to('sign in', 'user/login') ?></li> we will just ask symfony to create the module skeleton, and we will write the code ourselves. $ symfony init-module frontend user
Đã gửi cách đây 5462 ngàyc. Secure the updating request with a transaction save() method is a good opportunity to illustrate the implementation of transactions in symfony. Replace the code by:
d. Change the template the ->getInterestedUsers() method of the Question object works properly, it is time to simplify the _interested_user.php fragment by replacing: <?php echo count($question->getInterests()) ?> By <?php echo $question->getInterestedUsers() ?> e. Test the validity of the modification Run again the data import batch: $ cd /home/sfprojects/askeet/batch $ php load_data.php When creating the records of the Interest table, the sfPropelData object will use the overridden save() method and should properly update the related User records. Check it by requesting the home page and the detail of the first question: http://askeet/frontend_dev.php/ http://askeet/frontend_dev.php/question/show/id/XX f. 5.
Đã gửi cách đây 5462 ngàyb. Modify the Save() method of the Interest object Open the askeet/lib/model/Interest.php file and write in the following method: public function save($con = null) {
$ret = parent::save($con); // update interested_users in question table $question = $this->getQuestion(); $interested_users = $question->getInterestedUsers(); $question->setInterestedUsers($interested_users 1); $question->save($con); return $ret;
}The new save() method gets the question related to the current interest, and increments its interested_users field. Then, it does the usual save(), but because a $this->save(); would end up in an infinite loop, it uses the class method parent::save() instead.
Đã gửi cách đây 5462 ngày4. Modify the question Part II The $question->getInterests() call of the new fragment does a request to the database and returns an array of objects of class Interest. This is a heavy request for just a number of interested persons, and it might load the database too much. Remember that this call is also done in the listSuccess.php template, but this time in a loop, for each question of the list. It would be a good idea to optimize it. One good solution is to add a column to the Question table called interested_users, and to update this column each time an interest about the question is created. a. Add a field to the User object model Modify the askeet/config/schema.xml data model by adding to the ask_question table: <column name="interested_users" type="integer" default="0" /> Then rebuild the model: $ symfony propel-build-model We also need to update the actual database. To avoid writing some SQL statement, We should rebuild SQL schema and reload test data: $ symfony propel-build-sql $ mysql -u youruser -p askeet < data/sql/lib.model.schema.sql $ php batch/load_data.php Note: There is more than way to do it. Instead of rebuilding the database, you can add the new column to the MySQL table by hand: $ mysql -u youruser -p askeet -e "alter table ask_question add interested_users int default '0'"
Đã gửi cách đây 5462 ngày3. Don’t Repeat yourself One of the good principles of agile development is to avoid duplicating code.We probably noticed some duplicated code between the listSuccess.php template and the showSuccess.php template
<div class="interested_mark" id="mark_<?php echo $question->getId() ?>"> <?php echo count($question->getInterests()) ?>
</div> Create an _interested_user.php file in the askeet/apps/frontend/modules/question/templates/ directory with the following code: <div class="interested_mark" id="mark_<?php echo $question->getId() ?>">
<?php echo count($question->getInterests()) ?>
</div> Then, replace the original code in both templates (listSuccess.php and showSuccess.php) with:
<?php include_partial('interested_user', array('question' => $question)) ?>
Đã gửi cách đây 5462 ngày2. Modify the Model part I We can also consider that the full name is an attribute of the User object. This means that there should be a method in the User model allowing to retrieve the full name, instead of reconstructing it in an action. Let's write it. Open the askeet/lib/model/User.php and add in the following method: public function __toString() {
return $this->getFirstName().' '.$this->getLastName();
} The method__toString() instead of getFullName() or something similar. Because the __toString() method is the default method used by PHP5 for object representation as string. This means that we can replace the: posted by <?php echo $answer->getUser()->getFirstName().' '.$answer->getUser()->getLastName() ?> line of the askeet/apps/frontend/modules/question/templates/showSuccess.php template by a simpler posted by <?php echo $answer->getUser() ?>
Đã gửi cách đây 5462 ngàyc. Add some new test data Add some data for the answer and relevancy tables at the end of the data/fixtures/test_data.yml
Reload your data with: $ php batch/load_data.php Navigate to the action showing the first question to check http://askeet/frontend_dev.php/question/show/id/XX
Đã gửi cách đây 5462 ngàyb. Modify the ShowSuccess.php template The generated showSuccess.php template is not exactly what we need, so we will completely rewrite it. Open the
frontend/modules/question/templates/showSuccess.php file and replace
its content by:
The new part is the answers div. It displays all the answers to the question (using the simple $question->getAnswers() Propel method), and for each of them, shows the total relevancy, the name of the author, and the creation date in addition to the body. The format_date() is another example of template helpers for which an initial declaration is required. Learn more about this in http://www.symfony-project.org/book/1_0/13-I18n-and-L10n Note: Propel creates method names for linked tables by adding an 's' automatically at the end of the table name. Please forgive the ugly ->getRelevancys() method since it saves you several lines of SQL code.
Đã gửi cách đây 5462 ngàyChappter 04 Refactoring
1. Show the answer to the question The question/show action is dedicated to display the details of a question, provided that you pass it an id. To test it, just call: http://askeet/frontend_dev.php/question/show/id/2 a. A quick look at the question First, let's have a look at the show action, located in the askeet/apps/frontend/modules/question/actions/actions.class.php file: public function executeShow()
{ $this->question =
QuestionPeer::retrieveByPk($this->getRequestParameter('id'));
$this->forward404Unless($this->question); }
Learn more a bout this in the: http://propel.phpdb.org/docs/user_guide/ The result of this request is passed to the showSuccess.php template through the $question variable. The ->getRequestParameter('id') method of the sfAction object gets... the request parameter called id, whether it is passed in a GET or in a POST mode. For instance, if you require: http://askeet/frontend_dev.php/question/show/id/1/myparam/myvalue ...then the show action will be able to retrieve myvalue by requesting $this->getRequestParameter('myparam'). Note: The forward404Unless() method sends to the browser a 404 page if the question does not exist in the database.
Đã gửi cách đây 5462 ngày8. Modify the question/list template We can modify the question/list template in the listSuccess.php located in askeet/apps/frontend/modules/question/templates/
Refreshing the development homepage http://askeet/frontend_dev.php/ 9. Cleanup The propel-generate-crud command created some actions and templates that will not be needed. It's time to remove them. Actions to remove in askeet/apps/frontend/modules/question/actions/actions.class.php: - executeIndex - executeEdit - executeUpdate - executeCreate - executeDelete Template to remove in askeet/apps/frontend/modules/question/templates/: - editSuccess.phpĐã gửi cách đây 5462 ngày7. Accessing the data in the model The page displayed when requesting the list action of the question module is the result of the executeList() method in the 1 file: askeet/apps/frontend/modules/question/actions/action.class.php
- action file
askeet/apps/frontend/modules/question/templates/listSuccess.php - template. actions.class.php: public function executeList () {
$this->questions = QuestionPeer::doSelect(new Criteria());
} listSuccess.php: ... <?php foreach ($questions as $question): ?> <tr>
<td><?php echo link_to($question->getId(),
'question/show?id='.$question->getId()) ?></td>
<td><?php echo $question->getTitle() ?></td> <td><?php echo $question->getBody() ?></td> <td><?php echo $question->getCreatedAt() ?></td> <td><?php echo $question->getUpdatedAt() ?></td> </tr>
<?php endforeach; ?>
Đã gửi cách đây 5462 ngàyc. Launch the batch Type the command line $ cd /home/sfprojects/askeet/batch $ php load_data.php Check the modifications in the database by refreshing the development home page: http://askeet/frontend_dev.php Note: By default, the sfPropelData object deletes all data before loading the new ones. We can also append to the current data: $data = new sfPropelData(); $data->setDeleteCurrentData(false); $data->loadData(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures');
Đã gửi cách đây 5462 ngàyb. Data Import The batch has to: - read the YAML file - Create instances of the Propel objects - Create the related records in the tables of the linked database In symfony, we can do that with two lines of code, thanks to the sfPropelData object. Just add the following code before the final ?> in the askeet/batch/load_data.php script: $data = new sfPropelData(); $data->loadData(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures'); A sfPropelData object is created, and told to load all the data of a specific directory - our fixtures directory - into the database defined in the databases.yml configuration file.
Đã gửi cách đây 5462 ngày6. Create batch to populate the database The next step is to actually populate the database, and we wish to do that with a PHP script that can be called with a command line - a batch. a. Batch skeleton Create a file called load_data.php in the askeet/batch/ directory with the following content:
This script does nothing, or close to nothing: it defines a path, an application and an environment to get to a configuration, loads that configuration, and initializes the database manager.
tác giả
Tìm thêm với Google.com :
NHÀ TÀI TRỢ