logo
down
shadow

Yii2 - How to render the index view plus the create view all in the same page


Yii2 - How to render the index view plus the create view all in the same page

By : user2950892
Date : November 17 2020, 11:58 AM
hop of those help? Greetings, , I SOLVED IT BY MYSELF.
SITECONTROLLER CODE:
code :
public function actionIndex()
{
    return $this->redirect(Url::toRoute('tube/index'));
}
public function actionIndex()
{
    $searchModel = new TubeSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
    $model = new Tube();

    if ($model->load(Yii::$app->request->post())) {
        $model->save();
    }

    return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
        'model' => $model,
    ]);

}


Share : facebook icon twitter icon
Yii2: Passing index page to breadcrumbs in view and update actions

Yii2: Passing index page to breadcrumbs in view and update actions


By : user3754854
Date : March 29 2020, 07:55 AM
help you fix your problem It seems there is no LinkPager magic to do this by now but I managed to find a solution avoiding controller tweaking. Just edit view.php/update.php and add before breadcrumbs stuff:
code :
parse_str(parse_url(Yii::$app->request->referrer, PHP_URL_QUERY), $params);
$this->params['breadcrumbs'][] = ['label' => 'myLabel', 'url' => ['index', 'page' => isset($params['page']) ? $params['page'] : '']];
public function actionIndex()
{
    $searchModel = new BibliografiaSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    Yii::$app->session['myPage'] = Yii::$app->request->get('page');

    return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
    ]);
}
$this->params['breadcrumbs'][] = ['label' => 'myLabel', 'url' => ['index', 'page' => Yii::$app->session['myPage']]];
Yii2 - Render _search.php file inside index.php of a view

Yii2 - Render _search.php file inside index.php of a view


By : authorx
Date : March 29 2020, 07:55 AM
it helps some times i have a view folder called eventos in Yii2. This view is an image gallery. , SOLVED.
_view2.php code:
code :
use yii\base\view;
echo $this->render('_search', array('model'=>$searchModel));
I have mixed Create view and index view codes in one view. So, How to retrieve data from a database by that view in asp.

I have mixed Create view and index view codes in one view. So, How to retrieve data from a database by that view in asp.


By : Alessandro Rubino
Date : March 29 2020, 07:55 AM
I hope this helps you . 1. add the Enumerable list of row to use it with foreach, in the model in the entity folder:
code :
public partial class UserProfile
    {
        public int UserId { get; set; }
        public string UserName { get; set; }
        public string PostContent { get; set; }
        public IEnumerable<workingOnAddPost.Entity.UserProfile> UserProfilesCollection { get; set; }
public class HomeController : Controller
{
    private AddingPostEntities db = new AddingPostEntities();

    [HttpGet]
    public ActionResult Index()
    {
        ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

        //return View( db.UserProfiles.ToList());


        var model = new UserProfile() 
        {
            UserProfilesCollection = db.UserProfiles.ToList(), 
        };
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(UserProfile userprofile)
    {
        if (ModelState.IsValid)
        {
            db.UserProfiles.Add(userprofile);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(userprofile);
    }
       //
    // POST: /PostManager/Create
    public ActionResult About()
    {
        ViewBag.Message = "Your app description page.";

        return View();
    }

    public ActionResult Contact()
    {
        ViewBag.Message = "Your contact page.";

        return View();
    }

    // GET: /PostManager/Details/5

    public ActionResult Details(int id = 0)
    {
        UserProfile userprofile = db.UserProfiles.Find(id);
        if (userprofile == null)
        {
            return HttpNotFound();
        }
        return View(userprofile);
    }


    //
    // GET: /PostManager/Edit/5

    public ActionResult Edit(int id = 0)
    {
        UserProfile userprofile = db.UserProfiles.Find(id);
        if (userprofile == null)
        {
            return HttpNotFound();
        }
        return View(userprofile);
    }

    //
    // POST: /PostManager/Edit/5

    [HttpPost]
    public ActionResult Edit(UserProfile userprofile)
    {
        if (ModelState.IsValid)
        {
            db.Entry(userprofile).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(userprofile);
    }

    //
    // GET: /PostManager/Delete/5

    public ActionResult Delete(int id = 0)
    {
        UserProfile userprofile = db.UserProfiles.Find(id);
        if (userprofile == null)
        {
            return HttpNotFound();
        }
        return View(userprofile);
    }

    //
    // POST: /PostManager/Delete/5

    [HttpPost, ActionName("Delete")]
    public ActionResult DeleteConfirmed(int id)
    {
        UserProfile userprofile = db.UserProfiles.Find(id);
        db.UserProfiles.Remove(userprofile);
        db.SaveChanges();
        return RedirectToAction("Index");
    }

    protected override void Dispose(bool disposing)
    {
        db.Dispose();
        base.Dispose(disposing);
    }

}
        @using System.Linq;
    @model  workingOnAddPost.Entity.UserProfile
    @{

    };

    @*<p>*@

<script src="~/Scripts/jquery-2.1.1.min.js"></script>
<script src="~/Scripts/masonry.pkgd.min.js"></script>
<script src="~/Scripts/myScript.js"></script>

<link href="~/Content/Styles/font-awesome.css" rel="stylesheet" />
<link href="~/Content/Styles/main.css" rel="stylesheet" />
@*<div class="Button addcontent">
      <button type="button" >
          <em class="icon-plus"></em>
      </button>
</div>*@
    @section featured {
        <section class="featured">
            <div class="content-wrapper">
                <hgroup class="title">
                    <h1>@*ViewBag.Title.*@</h1>
                    <h2>@*ViewBag.Message*@</h2>
                </hgroup>
                <p>
                    To learn more about ASP.NET MVC visit
                    <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
                    The page features <mark>videos, tutorials, and samples</mark> to help you get the most from ASP.NET MVC.
                    If you have any questions about ASP.NET MVC visit
                    <a href="http://forums.asp.net/1146.aspx/1?MVC" title="ASP.NET MVC Forum">our forums</a>.
                </p>
            </div>
        </section>
    }

    <div class="Button addcontent">
        <button type="button">
            <em class="icon-plus"></em>
        </button>
    </div>

        @using (Html.BeginForm())
            {
            @Html.ValidationSummary(true)


            <div class="modal-addcontent">
                <div class="modal">
                    <div class="standardForm">
                        <h1>
                            Add new content
                        </h1>
                        <ul>
                            <li>
                                <h3>
                                    <label>
                                        Id=
                                    </label>
                                </h3>
                                <div class="editor-field">
                                    @Html.EditorFor(model => model.UserId)
                                    @Html.ValidationMessageFor(model => model.UserId)
                                </div>
                            </li>
                            <li>
                                <h3>
                                    <label>
                                        Name:
                                    </label>
                                </h3>
                                <div class="editor-field">
                                    @Html.EditorFor(model => model.UserName)
                                    @Html.ValidationMessageFor(model => model.UserName)
                                </div>
                            </li>
                            <li>
                                <h3>
                                    <label>
                                        Description
                                    </label>
                                </h3>

                                <div class="content">
                                    @Html.TextAreaFor(model => model.PostContent)
                                    @Html.ValidationMessageFor(model => model.PostContent)
                                </div>
                            </li>
                            <li>
                                <h3>
                                    <label>
                                        Image
                                    </label>
                                </h3>
                                <div>
                                    <input id="upload" type="file" />
                                </div>
                            </li>
                        </ul>
                        <div class="formFooter">
                            <div class="FooterButtons">
                                <button class="Button btn close-modalpopup" type="button">
                                    <span class="buttonText">
                                        Cancel
                                    </span>
                                </button>
                                <p>
                                    <button class="Button primary btn" type="submit" value="Create">
                                        <span class="buttonText">
                                            Create
                                        </span>
                                    </button>

                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            }
<h3>We suggest the following:</h3>
<ol class="round">
    <li class="one">
        <h5>Getting Started</h5>
        ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
        enables a clean separation of concerns and that gives you full control over markup
        for enjoyable, agile development. ASP.NET MVC includes many features that enable
        fast, TDD-friendly development for creating sophisticated applications that use
        the latest web standards.
        <a href="http://go.microsoft.com/fwlink/?LinkId=245151">Learn more…</a>
    </li>

    <li class="two">
        <h5>Add NuGet packages and jump-start your coding</h5>
        NuGet makes it easy to install and update free libraries and tools.
        <a href="http://go.microsoft.com/fwlink/?LinkId=245153">Learn more…</a>
    </li>

    <li class="three">
        <h5>Find Web Hosting</h5>
        You can easily find a web hosting company that offers the right mix of features
        and price for your applications.
        <a href="http://go.microsoft.com/fwlink/?LinkId=245157">Learn more…</a>
    </li>
</ol>
@*<table>*@
@foreach (var item in Model.UserProfilesCollection)
{

    <div id="main">
        <div id="main-inner">
            <div id="container" class="js-masonry" data-masonry-options='{ "columnWidth": ".grid-sizer", "itemSelector": ".item"}'>
                <div class="grid-sizer">
                <div class="item open-modal">
                    <p>
                        @Html.DisplayTextFor(Modelitem => item.PostContent)
                    </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
}
        @* </table>*@
Render Detail view page yii2 from search when there is 1 result

Render Detail view page yii2 from search when there is 1 result


By : Greeshma Gopi
Date : March 29 2020, 07:55 AM
Hope that helps In yii2 , after search if there is only 1 result how to automatically get in to the detail view page. , I think this will be it in case of basic usage of yii2 ..
code :
     $searchModel = new PostSearch();   // Search Model can be created by gii 
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        $count=    $dataProvider->getTotalCount();

              if($count==1){

                    $a =   $dataProvider->getModels();
                     $id = $a[0]['id'] ;    // accessing 2nd level array elements   or $dataProvider->getModels()[0]['id'];

                     return $this->render('view', [
                         'model' => $this->findModel($id), //findModel($id) is protected function in the controller
                     ]);

              }
how to render a view from controller1 into a view of controller2 yii2?

how to render a view from controller1 into a view of controller2 yii2?


By : hoffiee
Date : March 29 2020, 07:55 AM
I hope this helps you . from your index action you are not returning any model, you must return the model which you wan to access on your view page,
Note you can return multiple models also
code :
public function actionIndex()
    {
        $model  = User::find()->where(['name' => 'CeBe'])->one(); // dummy example

        return $this->render('index', ['model'=>$model]); // this can be used on your index page
    }
Related Posts Related Posts :
  • What is Object dictionary in CANOpen?
  • Example of orbBasic Indexed User Variables
  • convert to ABSOLUTE in logback
  • How to conditionally download file using p:fileDownload
  • Error on pod install
  • Set HTTP GET Parameters in Finagle
  • different attack that uses sql injection
  • How can I change my xampp username not as 'root'
  • AMQP Content header payload structure
  • Apache POI formula evaluation not working for Excel IF
  • How can I trace RESTEasy's dispatch?
  • Map Freezes on iOS 7 with Google Maps SDK 1.4
  • Comparing lists, is the subset list within the first list
  • Non-ascii character highlight in Sublime Text 2
  • Installing Magit in Aquamacs
  • Receiving error - System.Net.Mail.SmtpException: 4.3.2 try again later
  • Coreaudio render callback in monotouch
  • The command 'yarn --v' also initiates 'yarn install' and installs packages automatically. Why is this happening?
  • save multiple matches in a list (grep or awk)
  • Can a number register be used in a groff request?
  • Mapping FAQ with RASA for large dataset (2000+)
  • Fragment not receiving LiveData updates after remove + add
  • FitText.js makes text bigger rather than smaller
  • ARM - Implementing stack with load/store multiple register values
  • How to check if a ChromeCast Session is already in progress
  • ngForm inside a Carousel Slide in UI Bootstrap not working
  • Clearing attributes in Tritium
  • "vagrant up" failing: Vagrant VM failed to remain in the running state
  • ftsearch returning empty docs
  • What are the advantages of setting "hive.exec.parallel" to false in Hive ?
  • Creating a root certificate in FiddlerCore
  • How to access app.config in a blueprint?
  • DB2 RECORDSET table name converted to uppercase
  • Resizing the superview according to the subviews
  • IExpress - Disable Compression
  • Getting InvalidProtocolBufferException while running oozie job
  • What are the differences between Play run and start?
  • How can I share props in ReasonReact?
  • Task.Delay is skipped
  • Parsley.js Password Confirm doesn‘t work
  • How to get all registred 'browser:resource' in Plone
  • Overriding page_list controller inside a package in Concrete5.6.1.2
  • Robolectric 2.x - dependent jars are downloading while running the tests
  • Setting Flyout to Main Frame Navigation(Windows 8.1 app store)
  • Build project - Nuget Error
  • How to recover admin password for SonarQube
  • perforce Tagging and labelling files
  • How to pass data from one window to another in Titanium?
  • TeamCity CI - Make custom build output folder
  • Multi-tenant ServiceStack API, same deployment to respond to requests on different hostnames?
  • How to show downshift + popper on top of material-ui dialog?
  • jQuery file upload and RequireJS configuration
  • How to send the result of a select query to a message body of a mail in oracle 10G
  • Worklight common build failing with "Failed to update main HTML file"
  • pg_listening_channels() is not returning the channels name
  • Asset management in ZF2
  • Does the Firefox add-on sdk allow direct modification of the http response byte stream?
  • How to remove menu hardware key from your android app
  • Identifying programming language
  • Use shell commands to find Makefile.am in configure.ac
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org