About

Breaking

Wednesday 10 May 2017

Create a Posts Controller

Next, we’ll create a controller for our posts. The controller is where all the business logic for post interaction will happen. In a nutshell, it’s the place where you play with the models and get post-related work done. We’ll place this new controller in a file called PostsController.php inside the /app/Controller directory. Here’s what the basic controller should look like:


इसके बाद, हम अपने पदों के लिए नियंत्रक बना लेंगे। नियंत्रक है जहां पोस्ट इंटरेक्शन के लिए सभी व्यावसायिक तर्क होंगे। संक्षेप में, यह वह जगह है जहां आप मॉडल के साथ खेलते हैं और संबंधित कार्य पूरा करते हैं। हम इस नए नियंत्रक को एक एप / कंट्रोलर डायरेक्टरी के अंदर पोस्ट कंट्रोलर.एफ़पीपी नामक फाइल में रखेंगे। यहां बुनियादी नियंत्रक क्या दिखना चाहिए:


class PostsController extends AppController {
    public $helpers = array('Html', 'Form');
}

Now, let’s add an action to our controller. Actions often represent a single function or interface in an application. For example, when users request www.example.com/posts/index (which is the same as www.example.com/posts/), they might expect to see a listing of posts. The code for that action would look something like this:


अब, हमारे नियंत्रक के लिए एक कार्य जोड़ें। कार्य अक्सर किसी एक फ़ंक्शन या इंटरफ़ेस को किसी अनुप्रयोग में दर्शाता है। उदाहरण के लिए, जब उपयोगकर्ता www.Codes.com/posts/index का अनुरोध करते हैं (जो कि www.codes.com/posts/ के समान है), तो वे पोस्ट की सूची देख सकते हैं। उस क्रिया का कोड कुछ ऐसा दिखाई देगा: 



class PostsController extends AppController {
    public $helpers = array('Html', 'Form');

    public function index() {
        $this->set('posts', $this->Post->find('all'));
    }
}



By defining function index()
in our PostsController, users can access the logic there by
requesting www.example.com/posts/index. Similarly, if we were to
define a function called foobar(), users would be able to
access that at www.example.com/posts/foobar.
 
 
हमारे पोस्ट
 कंट्रोलर में फंक्शन इंडेक्स () को परिभाषित करके, उपयोगकर्ता 
www.example.com/posts/index का अनुरोध करके तर्क का उपयोग कर सकते हैं। इसी
 तरह, अगर हम फूबर () नामक फ़ंक्शन को परिभाषित करना चाहते हैं, तो 
उपयोगकर्ता www.example.com/posts/foobar पर उस तक पहुंच सकेंगे।
 

The single instruction in the action uses set() to pass data from the controller to the view (which we’ll create next). The line sets the view variable called ‘posts’ equal to the return value of the find('all') method of the Post model. Our Post model is automatically available at $this->Post because we’ve followed CakePHP’s naming conventions.


कार्रवाई में एकल अनुदेश नियंत्रक से डेटा को देखने के लिए सेट () सेट करता है (जो हम अगले बनायेंगे)। रेखा पोस्ट मॉडल की खोज ('सभी') विधि के रिटर्न मान के बराबर 'पोस्ट' वाले दृश्य वैरिएबल को सेट करता है। हमारा पोस्ट मॉडल स्वतः $ $-> पोस्ट पर उपलब्ध है क्योंकि हमने केकपीएचपी के नामकरण सम्मेलनों का पालन किया है।
  
 

No comments:

Post a Comment